vercel / vercel/ncc

ncc vs Serialport Part 1 - ESM

Open
#899 1 comment 0 reactions 0 assignees View on GitHub

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

  1. yarn init -y
  2. yarn add serialport@^9.2.8
  3. file index.mjs
import SerialPort from 'serialport'
  1. 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.