Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ensure that NodeJS backend is fully ESM-compatible #1328

@jacobwod

Description

@jacobwod

While an attempted routine dependency upgrade I run into some problems: I couldn't upgrade to query-string >=8. I got some unexpected errors and it seems to have to do with the way we import modules (EMS vs CommonJS). This got me baffled, as I thought that the new Backend was using ESM since start (after all there are no require() and we import all our packages).

But it turns out that there are some more steps which need to be taken into account. A nice list I found here says this:

Add "type": "module" to your package.json.
Replace "main": "index.js" with "exports": "./index.js" in your package.json.
Update the "engines" field in package.json to Node.js 14: "node": ">=14.16". (Excluding Node.js 12 as it's no longer supported)
Remove 'use strict'; from all JavaScript files.
Replace all require()/module.export with import/export.
Use only full relative file paths for imports: import x from '.'; → import x from './index.js';.
If you have a TypeScript type definition (for example, index.d.ts), update it to use ESM imports/exports.
Optional but recommended, use the node: protocol for imports.

So I'm creating this issue to get this on my radar and I'll attempt to fix it in the near future.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions