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

Issue importing a package with module:true #6

Open
reconbot opened this issue Jun 21, 2021 · 0 comments
Open

Issue importing a package with module:true #6

reconbot opened this issue Jun 21, 2021 · 0 comments

Comments

@reconbot
Copy link

I went to import @sindresorhus/slugify which uses module:true in it's pacakge.json and it's .js files are esm. Here's a simple test case.

import slugify from '@sindresorhus/slugify'

console.log(slugify('I ♥ Dogs'))

And when I run it

$ npx ts-eager test.js
(node:66787) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/wizard/src/telley-live/telley-api/test.js:1
import slugify from '@sindresorhus/slugify'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

My settings for esbuild are able to bundle it however.

import { build } from 'esbuild'

build({
  entryPoints: ['test.js'],
  outfile: 'output.js',
  bundle: true,
  plugins: [],
  platform: 'node',
  minify: false,
  target: ['node14'],
})
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