ts-eager
ts-eager copied to clipboard
Issue importing a package with module:true
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'],
})