diff --git a/src/index.js b/src/index.js index a6fb623e..0071a15f 100644 --- a/src/index.js +++ b/src/index.js @@ -531,7 +531,7 @@ function ncc ( const baseDir = dirname(filename); const pjsonPath = (baseDir === '.' ? '' : baseDir) + 'package.json'; if (assets[pjsonPath]) - assets[pjsonPath].source = JSON.stringify(Object.assign(JSON.parse(pjsonPath.source.toString()), { type: 'module' })); + assets[pjsonPath].source = JSON.stringify(Object.assign(JSON.parse(assets[pjsonPath].source.toString()), { type: 'module' })); else assets[pjsonPath] = { source: JSON.stringify({ type: 'module' }, null, 2) + '\n', permissions: defaultPermissions }; } diff --git a/test/cli.js b/test/cli.js index 514c01d1..84858c8a 100644 --- a/test/cli.js +++ b/test/cli.js @@ -11,6 +11,10 @@ args: ["run", "test/integration/test.ts"], expect: { code: 0 } }, + { + args: ["build", "test/fixtures/type-module/main.js", "-o", "tmp"], + expect: { code: 0 } + }, { args: ["build", "test/integration/test.ts", "-o", "tmp"], expect (code, stdout, stderr) { diff --git a/test/fixtures/type-module/main.js b/test/fixtures/type-module/main.js new file mode 100644 index 00000000..20973d83 --- /dev/null +++ b/test/fixtures/type-module/main.js @@ -0,0 +1,6 @@ +import { readFileSync } from 'fs'; + +readFileSync(new URL('./package.json', import.meta.url)); + +export var p = 5; + diff --git a/test/fixtures/type-module/package.json b/test/fixtures/type-module/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/test/fixtures/type-module/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +}