Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export for directives can't be resolved #10

Closed
knuthaug opened this issue Sep 16, 2022 · 5 comments · Fixed by #11
Closed

Export for directives can't be resolved #10

knuthaug opened this issue Sep 16, 2022 · 5 comments · Fixed by #11

Comments

@knuthaug
Copy link
Collaborator

knuthaug commented Sep 16, 2022

We are experiencing an issue with using @popeindustries/lit@1.0.4 as a "proxy" for exports from @popeindustries/lit-html.

import { unsafeHTML } from '@popeindustries/lit/directives/unsafe-html.js';

gives the error

error TS2305: Module '"@popeindustries/lit/directives/unsafe-html"' has no exported member 'unsafeHTML'.

Checking the file node_modules/@popeindustries/lit/directives/unsafe-html.js it contains

export * from '@popeindustries/lit-html/directives/unsafe-html.js';

This file path points to nothing in the package @popeindustries/lit-html on disc in node_modules. @popeindustries/lit-html has src and vendor directories (and src/vendor) which contains directives. The export map of @popeindustries/lit-html lists directives as

"./directives/*": {
      "development": "./src/vendor/directives/*",
      "default": "./vendor/directives/*"
  }

which seem to point to the right place. So why can't the typescript compiler resolve this import? Using the import directly from lit-html gives the same error, while pointing directly to e.g. the vendor directory

import { unsafeHTML } from '@popeindustries/lit-html/vendor/directives/unsafe-html.js';

works as intended. This leads me to think that our project can't read/understand the exports map correctly, but shouldn't node 18.9 and typescript 4.8.3 be able to do that? On closer inspection it seems that it might be the wildcard export map that isn't understood, because addition of e.g

"./directives/async-append.js": {
      "development": "./src/vendor/directives/async-append.js",
      "default": "./vendor/directives/async-append.js"
    }

Seems to work well.

node version: 18.9.0
typescript version: 4.8.3

@knuthaug
Copy link
Collaborator Author

knuthaug commented Sep 16, 2022

Additional testing

'@popeindustries/lit-html/vendor/directives/unsafe-html.js

works well, while

'@popeindustries/lit-html/directives/unsafe-html.js

Does not. Is there som specific config needed in our project to make this work?

@popeindustries
Copy link
Owner

Interesting. This seems to works correctly in Node/dvlp/esbuild, but not yet in TypeScript. The fix has been merged (microsoft/TypeScript#49644), but evidently not yet released. I guess the only option is to manually add each export

@popeindustries
Copy link
Owner

Correction: TypeScript can't resolve aliases via exports (./directives.js => ./vendor/directives.js), so need to create modules that alias to vendor module.

@pumano
Copy link

pumano commented Sep 19, 2022

same problem with lit-html-server, have problems with typings resolve in TypeScript:

Cannot find module '@popeindustries/lit-html-server' or its corresponding type declarations.ts(2307)

@popeindustries
Copy link
Owner

Thanks @pumano, I'll look into that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants