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

experimental-specifier-resolution=node breaks symlinked (e.g. pnpm) package structure #42244

Closed
tstewart-klaudhaus opened this issue Mar 7, 2022 · 6 comments

Comments

@tstewart-klaudhaus
Copy link

Version

17.6.0 and 16.14.0

Platform

Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Tue Aug 24 20:28:00 PDT 2021; root:xnu-6153.141.40~1/RELEASE_X86_64 x86_64

Subsystem

internal/modules/esm/resolve

What steps will reproduce the bug?

  • ensure pnpm is installed globally

  • In a new, blank directory, add the following package.json:

{
  "dependencies": {
    "@lit-labs/ssr": "^2.0.3"
  },
  "type": "module"
} 
  • Run pnpm install

  • Run node (interactive with no flags), and the following works:

> let { installWindowOnGlobal } = await import("@lit-labs/ssr/lib/dom-shim.js")
undefined
  • Run node --experimental-specifier-resolution=node and it no longer works
> let { installWindowOnGlobal } = await import("@lit-labs/ssr/lib/dom-shim.js")
Uncaught:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'node-fetch' imported from /Users/tstewart/dev/ex-spec-res-issue/node_modules/@lit-labs/ssr/lib/dom-shim.js
    at __node_internal_captureLargerStackTrace (node:internal/errors:465:5)
    at new NodeError (node:internal/errors:372:5)
    at packageResolve (node:internal/modules/esm/resolve:901:9)
    at moduleResolve (node:internal/modules/esm/resolve:950:20)
    at defaultResolve (node:internal/modules/esm/resolve:1166:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:536:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:250:18) {
  code: 'ERR_MODULE_NOT_FOUND'
}

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

I expect the flag to only affect the behaviour relating to file extensions.

What do you see instead?

The flag also produces a changed behaviour in terms of the module search path with symlinked modules.

Additional information

I would expect the --experimental-specifier-resolution flag to only affect the behaviour with regard to the ".js" extension, at least that is what I am aiming at, so I can use Typescript output without post-processing all files to have ".js" extensions or similar workaround. This works fine if I use the "shamefully-hoist" flag in pnpm installation, so that all packages are flattened at the top level of node_modules. If that is indeed the intended behaviour of --experimental-specifier-resolution - i.e. that it should change BOTH the file extension behaviour AND the symlinked path behaviour, then is it possible in any way to get the desired behaviour (working without ".js" extensions) without the undesired behaviour (different interpretation of symlinked paths).

@meixg
Copy link
Member

meixg commented Mar 7, 2022

This may have been solved by #42197, and a duplicate of #42195

Can you please try on the master branch to see if it work?

@tstewart-klaudhaus
Copy link
Author

Yes that does sound very similar, thanks. I'm unfamiliar with building node from source, but will address this over the coming day or so to check.

@aduh95
Copy link
Contributor

aduh95 commented Mar 7, 2022

You can also use one of the nightly builds (the most recent one at the time of writing can be found at https://nodejs.org/download/nightly/v18.0.0-nightly202203074158d62dec/ and I think it contains does contain the fix), so you don't have to set up a whole dev env :)

@tstewart-klaudhaus
Copy link
Author

Yep that fixes it, many thanks. So this will be in the 18.0.0 release? Is it likely to be back-ported to any other major versions? Just wanting to understand my users' system requirements once this rolls out.

tstewart-klaudhaus added a commit to metaliq/metaliq that referenced this issue Mar 7, 2022
Revert to symlinked node_modules (works with Node 18, see nodejs/node#42244).
Add missing peer deps.
@aduh95
Copy link
Contributor

aduh95 commented Mar 7, 2022

It will be in v18.0.0, and it should also be backported to the next v17.x release, and later in a v16.x release. Good to hear that fixed it for you, closing :)

@tstewart-klaudhaus
Copy link
Author

Thanks again, great result.

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

No branches or pull requests

5 participants