Skip to content

SyntaxError: Unexpected identifier 'assert' on build #69

@hejops

Description

@hejops

Node.js removed support for import assertions a while ago, so rollup.config.mjs is technically invalid now. I thought I could work around this by simply replacing assert with with, but rollup still thinks there is an assert somewhere.

I'm on node 23.7.0. Presumably versions >= 22 will be affected.

To reproduce:

cd /tmp
rm -rf discojs
git clone https://github.com/aknorw/discojs
cd discojs
yarn install

yarn rollup --version

yarn build || :
sed -i 's/assert/with/' rollup.config.mjs
yarn build || :
Cloning into 'discojs'...
remote: Enumerating objects: 1150, done.
remote: Counting objects: 100% (217/217), done.
remote: Compressing objects: 100% (116/116), done.
remote: Total 1150 (delta 128), reused 101 (delta 101), pack-reused 933 (from 1)
Receiving objects: 100% (1150/1150), 1.18 MiB | 2.33 MiB/s, done.
Resolving deltas: 100% (762/762), done.
yarn install v1.22.22
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
warning rollup-plugin-ts@3.4.5: The engine "pnpm" appears to be invalid.
warning browserslist-generator@2.1.0: The engine "pnpm" appears to be invalid.
[4/5] Linking dependencies...
warning " > typedoc@0.19.2" has incorrect peer dependency "typescript@3.9.x || 4.0.x".
[5/5] Building fresh packages...
$ husky
Done in 1.20s.
yarn run v1.22.22
$ /tmp/discojs/node_modules/.bin/rollup --version
rollup v4.21.0
Done in 0.16s.
yarn run v1.22.22
$ rimraf dist && rollup -c
[!] SyntaxError: Unexpected identifier 'assert'
    at compileSourceTextModule (node:internal/modules/esm/utils:338:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:106:18)
    at ModuleLoader.#translate (node:internal/modules/esm/loader:473:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:520:27)
    at ModuleJob._link (node:internal/modules/esm/module_job:115:19)


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
yarn run v1.22.22
$ rimraf dist && rollup -c
[!] SyntaxError: Unexpected identifier 'assert'
    at compileSourceTextModule (node:internal/modules/esm/utils:338:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:106:18)
    at ModuleLoader.#translate (node:internal/modules/esm/loader:473:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:520:27)


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions