Open h-unterp opened 2 years ago
Thanks for the report @h-unterp. Just to clarify, you are encountering this issue when working with packages which have "type": "module"
set in package.json
- is that correct?
@mf-bruce Yes this happens in esm projects, and maybe it can be solved by:
nps
runs, detect if it's inside an esm projectIt would be great to add esm support, otherwise esm modules cannot be imported from package-scripts.js
. More and more npm packages are migrating to esm and they are distributing esm only.
/Users/hp/.nvm/versions/node/v16.15.0/lib/node_modules/@markforged/nps/dist/bin-utils/index.js:200 var mod = require(modulePath); ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/hp/dev/fiduc_api/functions/package-scripts.js from /Users/hp/.nvm/versions/node/v16.15.0/lib/node_modules/@markforged/nps/dist/bin-utils/index.js not supported. package-scripts.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename package-scripts.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/hp/dev/fiduc_api/functions/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
code: 'ERR_REQUIRE_ESM' }