ncc vs Serialport Part 1 - ESM
Open
Nobody has claimed this yet.
bug
- Dominant language
- JavaScript
- Stars
- 9.8k
- Forks
- 326
- PR merge metrics
- No merged PRs in 30d
Description
ncc apparently does not handle require inside SerialPort (https://www.npmjs.com/package/serialport) correctly in ESM mode
- yarn init -y
- yarn add serialport@^9.2.8
- file index.mjs
import SerialPort from 'serialport'
ncc build .\index.mjs -s -C --target es2020
node dist/index.mjs
ReferenceError: require is not defined in ES module scope, you can use import instead
at Object.5 (file:///C:/temp/sp_test/webpack:/sp_test/node_modules/@serialport/bindings/lib/win32.js:1:1)
at __nccwpck_require__ (file:///C:/temp/sp_test/webpack:/sp_test/webpack/bootstrap:21:1)
at Object.851 (file:///C:/temp/sp_test/webpack:/sp_test/node_modules/@serialport/bindings/lib/index.js:6:1)
at __nccwpck_require__ (file:///C:/temp/sp_test/webpack:/sp_test/webpack/bootstrap:21:1)
at Object.618 (file:///C:/temp/sp_test/webpack:/sp_test/node_modules/serialport/lib/index.js:2:1)
at __nccwpck_require__ (file:///C:/temp/sp_test/webpack:/sp_test/webpack/bootstrap:21:1)
at file:///C:/temp/sp_test/dist/index.mjs:3253:68
at file:///C:/temp/sp_test/dist/index.mjs:3258:3
at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
at async Promise.all (index 0)
ncc 0.33.3
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with index.mjs, serialport@^9.2.8, and the ncc build command, then inspect the generated dist/index.mjs and the referenced SerialPort files under node_modules/@serialport/bindings and node_modules/serialport. Done means the generated ESM file runs under Node.js without the reported require ReferenceError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100