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

The module imported with the path alias specified in paths in tsconfig.json is not being bundled #3160

Closed
mattp0123 opened this issue Jun 14, 2023 · 4 comments

Comments

@hyrious
Copy link

hyrious commented Jun 14, 2023

I guess this is because --packages=external marks every path not starting with [./] as external before the bundle resolution works. repl link without that option

Note that baseUrl is prepended to the aliased path, so you should avoid duplicate segments between them.

@mattp0123
Copy link
Author

@hyrious thank you for the reply, I trying to bundle my node app to esm syntax output (mjs), any suggestion?

@hyrious
Copy link

hyrious commented Jun 14, 2023

One possible way is to use --external:pkgname to manually exclude dependencies instead of using packages=external. In 99% of the cases, you only have to exclude the keys from your package.json/dependencies so:

let pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'))
esbuild.build({ ...options, external: Object.keys(pkg.dependencies) })

@mattp0123
Copy link
Author

@hyrious Thank you, I also add a banner option to avoid this issue

{
  ...options,
  banner: {
    js: "import { createRequire } from 'module';const require = createRequire(import.meta.url);",
  },
}

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

2 participants