SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.15k stars 659 forks source link

[Bug]: Node 20.9.0 - SyntaxError: Unexpected token 'with' in locale/index.js - adminjs #1683

Open mjmcgrath2010 opened 1 month ago

mjmcgrath2010 commented 1 month ago

Contact Details

mike@grocerslist.com / engineering@grocerslist.com

What happened?

SyntaxError: Unexpected token 'with' when upgrading Node to v20.9.0 and adminjs@7.8.7

I cannot boot my server due to a syntax error stemming from this file:

https://github.com/SoftwareBrothers/adminjs/blob/master/src/locale/index.ts#L3

My tsconfig.json is proper and adheres to documentation, using esm & nodenext, etc..., however, it seems like this forward-looking vision of "ESM is the new future" may hold true, but sadly, it appears that is indeed not the case for with { type: 'json' } syntax sad to report.

Can this be fixed as soon as possible? This package pushes everyone to adhere to ESM, a new and actively changing spec, as opposed to CJS, which has been battle-tested for years with wide support, presumably to be on the "cutting edge of an envisioned future." --- IMO, it is pretty frustrating for an npm package to have control over how I want my modules to be implemented already; the least you can do is ensure that YOUR forward-thinking package adheres to the everchanging ecosystem. Sorry to be blunt, I find this wild.

If we can get this resolved within the next couple of months we'd still be interested in the enterprise version, but if not, it's worth the headache, honestly.

Bug prevalence

Its your bug

AdminJS dependencies version

"@adminjs/design-system": "^4.1.1",
"@adminjs/express": "^6.1.0",
"@adminjs/mongoose": "^4.1.0",
"@adminjs/themes": "^1.0.1",
"adminjs": "^7.8.7",

"typescript": "^5.4.5"

What browsers do you see the problem on?

Firefox, Chrome, Safari, Microsoft Edge

Relevant log output

App [server:1] exited with code [1] via signal [SIGINT]
2024-07-17-13:25:46 PM2                 | App [server:1] starting in -fork mode-
2024-07-17-13:25:46 PM2                 | App [server:1] online
2024-07-17-13:25:46 1|server            | file:///Users/mmcgrath/Development/GrocersList/node_modules/adminjs/lib/locale/index.js:1
2024-07-17-13:25:46 1|server            | import deLocale from './de/translation.json' with { type: 'json' };
2024-07-17-13:25:46 1|server            |                                              ^^^^
2024-07-17-13:25:46 1|server            | SyntaxError: Unexpected token 'with'
2024-07-17-13:25:46 1|server            |     at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:118:18)
2024-07-17-13:25:46 1|server            |     at callTranslator (node:internal/modules/esm/loader:273:14)

Relevant code that's giving you issues

https://github.com/SoftwareBrothers/adminjs/blob/master/src/locale/index.ts#L3

https://github.com/SoftwareBrothers/adminjs/blob/master/package.json#L64 < (not true, please fix)
dziraf commented 1 month ago

In Node 20.10.0 the import syntax's changed from import ... assert to import ... with. You can either upgrade Node to 20.10.0 or downgrade adminjs to 7.8.1.

Do note that the current LTS version is 20.15.1. I'll update package.json to explicitly say that node version must be greater or equal 20.10.0.

While I agree that Node's implementation of ESM is not the best, we'd been forced to migrate ourselves due to our dependencies abandoning CJS.