kpdecker / jsdiff

A javascript text differencing implementation.
BSD 3-Clause "New" or "Revised" License
7.92k stars 496 forks source link

SyntaxError: Unexpected identifier 'assert' during Grunt buld #537

Closed vela1606 closed 3 weeks ago

vela1606 commented 1 month ago

Error:

Running "exec:rollup" (exec) task
>> [!] SyntaxError: Unexpected identifier 'assert'
>>     at compileSourceTextModule (node:internal/modules/esm/utils:337:16)
>>     at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:163:18)
>>     at callTranslator (node:internal/modules/esm/loader:429:14)
>>     at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:435:30)
>>     at async ModuleJob._link (node:internal/modules/esm/module_job:106:19)
>> Exited with code: 1.
>> Error executing child process: Error: Process exited with code 1.
Warning: Task "exec:rollup" failed. Use --force to continue.

Fix: Edit rollup.config.mjs Change: import pkg from './package.json' assert { type: 'json' }; To: import pkg from './package.json' with { type: 'json' };

ExplodingCabbage commented 3 weeks ago

Aha - it took me a while to figure out why this worked on my machine but not yours, but it must be that you're on Node v22, which has dropped support for "import assertions" (the assert { type: 'json' }; syntax) in favour of "import attributes" (the with { type: 'json' } syntax). I'll make the change. (I might also write up a self-answered Stack Overflow question about this; there's bound to be a bajillion projects caught by the same issue when they upgrade to Node 22.)

ExplodingCabbage commented 2 weeks ago

For the record, I asked and self-answered a Stack Overflow question about this error: https://stackoverflow.com/q/78876691/1709587