You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When this code is executed, Node.js throws the following error:
(node:14784) 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)
.../node_modules/used-pm/dist/esm/index.js:1
export default () => {
^^^^^^
SyntaxError: Unexpected token 'export'
Steps To Reproduce
Go into the new directory and create a package.json file with the following contents:
Run npm run foo - This command should fail with the following error:
$ npm run foo
> foo
> node bar.mjs(node:14989) 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).../node_modules/used-pm/dist/esm/index.js:1export default () => {^^^^^^SyntaxError: Unexpected token 'export'...
After the last fix, javascript files stopped working.
This is now fixed by splitting the source files into separate commonJS and ESM files.
closed#22, closed#23
After the last fix, JavaScript files stopped working.
This is now fixed by splitting the source files into separate commonJS and ESM files.
Resolves#22Resolves#23
### Additional Notes
The following cases are working:
```
Test in Common JS: 'pnpm exec node foo.js':
{ name: 'pnpm', version: '8.4.0' }
Test in Common JS: 'pnpm exec node foo.cjs':
{ name: 'pnpm', version: '8.4.0' }
Test in ESM JS: 'pnpm exec node foo.mjs':
{ name: 'pnpm', version: '8.4.0' }
Test in TS: 'pnpm exec ts-node foo.ts':
{ name: 'pnpm', version: '8.4.0' }
Test in Common TS: 'pnpm exec ts-node foo.cts':
{ name: 'pnpm', version: '8.4.0' }
```
I am considering adding unit tests for this script (see #24).
Description of the bug
used-pm/README.md
Lines 27 to 33 in f724043
When this code is executed, Node.js throws the following error:
Steps To Reproduce
Go into the new directory and create a
package.json
file with the following contents:Run
npm install [email protected]
Create a
bar.mjs
file with the following contents:Run
npm run foo
- This command should fail with the following error:Additional Information
In order for a file with a
.js
extension to be interpreted as an ESM, you need to add"type": "module"
to thepackage.json
file.Node.js and TypeScript will detect the
"type": "module"
in thepackage.json
file in the nearest parent directory.see
package.json
and file extensions - Modules: Packages | Node.js v20.1.0 DocumentationIn the case of used-pm, I would suggest creating a
dist/esm/package.json
file after the build with the following content:The text was updated successfully, but these errors were encountered: