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

subpath import cannot resolve node internal module #3485

Closed
xfournet opened this issue Nov 11, 2023 · 0 comments
Closed

subpath import cannot resolve node internal module #3485

xfournet opened this issue Nov 11, 2023 · 0 comments

Comments

@xfournet
Copy link

When bundling, a subpath import to a node internal module (eg like 'stream') is not resolved by esbuild, leading to an error.

Reproduction case

package.json

{
  "type": "module",
  "scripts": {
    "run-direct": "node main-direct.js",
    "run-subpathimport": "node main-subpathimport.js",
    "bundle-direct": "esbuild --bundle --platform=node main-direct.js",
    "bundle-subpathimport": "esbuild --bundle --platform=node main-subpathimport.js"
  },
  "imports": {
    "#stream": {
      "node": "stream",
      "default": "./stub.js"
    }
  },
  "devDependencies": {
    "esbuild": "0.19.5"
  }
}

main-direct.js

import * as stream from 'stream';

console.log(Object.keys(stream));

main-subpathimport.js

import * as stream from '#stream';

console.log(Object.keys(stream));

stub.js

export const test = 'test';

npm run run-direct, npm run run-subpathimport, npm run bundle-direct all works correctly

npm run bundle-subpathimport fails with error

✘ [ERROR] Could not resolve "#stream"

main-subpathimport.js:1:24:
  1 │ import * as stream from '#stream';
    ╵                         ~~~~~~~~~

The remapped path "stream" could not be resolved:

package.json:11:14:
  11 │       "node": "stream",
     ╵               ~~~~~~~~

You can mark the path "#stream" as external to exclude it from the bundle, which will remove this
error and leave the unresolved path in the bundle.

The error The remapped path "stream" could not be resolved should not happen in that case ?

@evanw evanw closed this as completed in 83e8c7f Nov 19, 2023
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

1 participant