Skip to content

Build Breakage on Latest NodeJS #97

@curran

Description

@curran

What is this error about?

> rm -rf dist && rollup -c

[!] SyntaxError: Unexpected identifier 'assert'
    at compileSourceTextModule (node:internal/modules/esm/utils:337:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:166:18)
    at callTranslator (node:internal/modules/esm/loader:437:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:443:30)

ChatGPT Insights

The error you encountered, SyntaxError: Unexpected identifier 'assert', relates to changes in Node.js 22. Specifically, Node.js 22 deprecated the use of import assertions, such as assert { type: 'json' }. This syntax was replaced by a new import attribute style using with { type: 'json' }【7†source】【8†source】【9†source】.

If you're using Rollup, the error could arise from plugins or config files still relying on the old import assertion syntax. To fix this issue, you can try:

  1. Modify imports: Update your Rollup config or other modules to use the new syntax, e.g., import pkg from './package.json' with { type: 'json' };.
  2. Downgrade Node.js: Temporarily switch to Node.js version 20 or 21, which still supports the old syntax【9†source】【10†source】.
  3. Check plugin compatibility: Ensure all Rollup plugins you're using are updated to support Node.js 22 changes.

This change in Node.js affects tools like Vite, Rollup, and others when dealing with JSON imports, so ensuring compatibility across your build system is crucial.

Temporary Solution

Solved it by downgrading Node so I could do this one release:

Full original error trace:

curran@liberation:~/repos/graph-data-structure$ npm publish

> graph-data-structure@4.1.0 prepublishOnly
> npm run build


> graph-data-structure@4.1.0 build
> rm -rf dist && rollup -c

[!] SyntaxError: Unexpected identifier 'assert'
    at compileSourceTextModule (node:internal/modules/esm/utils:337:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:166:18)
    at callTranslator (node:internal/modules/esm/loader:437:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:443:30)


npm error code 1
npm error path /home/curran/repos/graph-data-structure
npm error command failed
npm error command sh -c npm run build
npm error A complete log of this run can be found in: /home/curran/.npm/_logs/2024-10-23T15_45_16_581Z-debug-0.log

Temporary solution:

curran@liberation:~/repos/graph-data-structure$ nvm install 20
Downloading and installing node v20.18.0...
Downloading https://nodejs.org/dist/v20.18.0/node-v20.18.0-linux-x64.tar.xz...
####################### 100.0%
Now using node v20.18.0 (npm v10.8.2)
curran@liberation:~/repos/graph-data-structure$ npm publish

> graph-data-structure@4.1.0 prepublishOnly
> npm run build


> graph-data-structure@4.1.0 build
> rm -rf dist && rollup -c


src/index.ts → dist/index.cjs...
(node:798302) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
created dist/index.cjs in 2.2s

src/index.ts → dist/index.mjs...
created dist/index.mjs in 1.7s

src/index.ts → dist/index.umd.js...
created dist/index.umd.js in 1.6s
npm notice
npm notice 📦  graph-data-structure@4.1.0
npm notice Tarball Contents
npm notice 1.1kB LICENSE
npm notice 8.6kB README.md
npm notice 5.8kB dist/index.cjs
npm notice 8.7kB dist/index.d.cts
npm notice 8.7kB dist/index.d.mts
npm notice 5.7kB dist/index.mjs
npm notice 8.7kB dist/index.umd.d.ts
npm notice 5.9kB dist/index.umd.js
npm notice 2.2kB package.json
npm notice Tarball Details
npm notice name: graph-data-structure
npm notice version: 4.1.0
npm notice filename: graph-data-structure-4.1.0.tgz
npm notice package size: 12.5 kB
npm notice unpacked size: 55.5 kB
npm notice shasum: a0e6405ce7c7dc9d37493718c8e32abee254bf3e
npm notice integrity: sha512-hGkRDE94buVER[...]1NN5ldojKQajg==
npm notice total files: 9
npm notice
npm notice Publishing to https://registry.npmjs.org/ with tag latest and default access
+ graph-data-structure@4.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions