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

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './log.js' is not defined by "exports" #28

Open
schlichtanders opened this issue Mar 21, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@schlichtanders
Copy link

Describe the bug
I just wanted to try out reejs on npm and it fails to build its own initialization.

To Reproduce
Steps to reproduce the behavior:

  1. step init
 reejs init esm-test
✓ https://esm.sh/v132/@clack/[email protected]?bundle in 1.852s
✓ https://esm.sh/v132/[email protected]?bundle in 1.602s
✓ https://esm.sh/v132/[email protected]?bundle in 2.15s
✓ https://esm.sh/v132/[email protected]?bundle in 3.68s
✓ https://esm.sh/v132/[email protected]?bundle in 1.98s

╭────────────────────────────────╮
│                                │
│   Welcome to Reejs Framework   │
│                                │
╰────────────────────────────────╯

┌  Let's create a new project!

◇  What would we create your next project?
│  ./esm-test

◇  Choose the features you want to include in your project
│  Preact (compat), Twind CSS, Serve Static Files

◇  Which package manager do you want to use (alongside URL Imports)?
│  npm

◇  Should we install dependencies for you?
│  Yes





└  Let's get started!
  1. step build
$ cd esm-test
$ npm run build       

> [email protected] build
> reejs packit node

node:internal/modules/esm/resolve:303
  return new ERR_PACKAGE_PATH_NOT_EXPORTED(
         ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './log.js' is not defined by "exports" in /home/myhome/esm-test/node_modules/@reejs/utils/package.json imported from /home/myhome/esm-test/node_modules/reejs/src/cli/index.js
    at exportsNotFound (node:internal/modules/esm/resolve:303:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:650:9)
    at packageResolve (node:internal/modules/esm/resolve:836:14)
    at moduleResolve (node:internal/modules/esm/resolve:910:20)
    at defaultResolve (node:internal/modules/esm/resolve:1130:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v20.11.1

Expected behavior
The package should be buildable after init, or the error should at least be understandable.

Desktop (please complete the following information):

  • OS: NixOS (Linux)
  • Browser no browser
  • Version [e.g. 22]
$ reejs doctor       
[reejs] Doctor
[RUNTIME] node
[VERSION] 0.17.0
[NODE_VER] 20.11.1
[REEJS_CACHE] 0 files
[REEJS_DIR] /home/[REDACTED]/.npm-packages/lib/node_modules/reejs/.reejs , /home/[REDACTED]/.julia/dev/tmp/esm-test/esm-test/.reejs
[REEJS_DIR_EXISTS] false
[PWD] /home/[REDACTED]/esm-test
[USER_AGENT] Node/v20.11.1 (reejs/0.17.0)
@schlichtanders schlichtanders added the bug Something isn't working label Mar 21, 2024
@renhiyama
Copy link
Contributor

Will be looking into this bug soon. Thanks for reporting this error 👍

@renhiyama
Copy link
Contributor

This issue occurs due to my new implementation of not download reejs own dependencies via npm, instead downloading it via URL imports.
Since URL imports makes you/me specifically import/download files, it backfired on me 😅.
I'll try to publish a new update for reejs within a few days, that should fix most of the problems, as well as introduce some new features!

@renhiyama
Copy link
Contributor

As for you, you can delete @reejs/* dependencies from node modules folder, and install them again via npm.

@renhiyama
Copy link
Contributor

Hey @schlichtanders, could you please try creating a new project with the latest Reejs version v0.20 to see if error still occurs? If it doesn't lmk, and I'll close this issue :)

@schlichtanders
Copy link
Author

I can confirm - npm run build runs through now without an error 👍

@renhiyama
Copy link
Contributor

could u try npm run dev ?

@schlichtanders
Copy link
Author

npm run dev fails


PACKIT  🍱 v0.20.0 - node

➜  📦 in 0.509s
➜  press h to show help
node:internal/url:1371
throw new ERR_INVALID_FILE_URL_HOST(platform);
^

TypeError [ERR_INVALID_FILE_URL_HOST]: File URL host must be "localhost" or empty on linux
at getPathFromURLPosix (node:internal/url:1371:11)
at fileURLToPath (node:internal/url:1394:50)
at getPackageScopeConfig (node:internal/modules/esm/package_config:35:50)
at packageResolve (node:internal/modules/esm/resolve:807:25)
at moduleResolve (node:internal/modules/esm/resolve:910:20)
at defaultResolve (node:internal/modules/esm/resolve:1130:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
at ModuleJob._instantiate (node:internal/modules/esm/module_job:152:57)
at async ModuleJob.run (node:internal/modules/esm/module_job:214:5) {
code: 'ERR_INVALID_FILE_URL_HOST'
}

Node.js v20.11.1

@renhiyama
Copy link
Contributor

Ah that's one of the other issues that we have. After starting packit in dev mode, type a to disable caching and d to enable debug mode, and then r to re-run packit again.
By default packit doesn't pack stuff up when u run the command, unless it never packed your project before - then it would have packed it.

@renhiyama
Copy link
Contributor

Normally that error occurs if there's two or more slashes together in any import statement.
Here's a small reproduction:

> await import("//hm/ok.js")
Uncaught:
TypeError [ERR_INVALID_FILE_URL_HOST]: File URL host must be "localhost" or empty on linux
    at getPathFromURLPosix (node:internal/url:1447:11)
    at fileURLToPath (node:internal/url:1470:50)
    at finalizeResolution (node:internal/modules/esm/resolve:245:12)
    at moduleResolve (node:internal/modules/esm/resolve:924:10)
    at defaultResolve (node:internal/modules/esm/resolve:1148:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:322:34) {
  code: 'ERR_INVALID_FILE_URL_HOST',
  input: 'file://hm/ok.js',
  module: 'file:///home/ren/repl'
}
> await import("/hm/ok.js")
Uncaught:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/hm/ok.js' imported from /home/ren/repl
    at finalizeResolution (node:internal/modules/esm/resolve:264:11)
    at moduleResolve (node:internal/modules/esm/resolve:924:10)
    at defaultResolve (node:internal/modules/esm/resolve:1148:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:322:34)
    at importModuleDynamically (node:repl:466:39)
    at importModuleDynamicallyWrapper (node:internal/vm/module:431:21) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///hm/ok.js'
}

Ree.js isn't foolproof - sometimes halfway downloaded/failed dependencies maybe forwarded back to packit - which would generate similar invalid import statements. The worst part is trying to debug it - nodejs didnt provide anything useful till this point: nodejs/node#49571

It was fixed in this PR in nodejs: nodejs/node#49571

@schlichtanders
Copy link
Author

Thank you for all your help.

I am off to defining import maps myself manually (I also have difficulties with jspm ;-) ), and don't have further time to try with reejs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants