fastify-uws
fastify-uws copied to clipboard
Export both CJS and ESM in library
I get an error when I try to import your library, because it's not properly packaged up for both ESM and CJS module definitions.
You can setup your package.json like this to produce both a CJS and ESM bundle:
{
"scripts": {
"build": "npx tsc --module commonjs --outDir dist/cjs && npx tsc --module esnext --outDir dist/esm"
},
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/cjs/index.d.ts",
}
It should produce a dist folder like this:
If I have some time, and you don't get to this first I will open a PR to fix this.
Error details:
Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/.pnpm/[email protected]/node_modules/tempy/index.js from /node_modules/.pnpm/@[email protected]/node_modules/@geut/fastify-uws/dist/server.cjs not supported.
Instead change the require of index.js in /node_modules/.pnpm/@[email protected]/node_modules/@geut/fastify-uws/dist/server.cjs to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at Object.<anonymous> (/node_modules/.pnpm/@[email protected]/node_modules/@geut/fastify-uws/dist/server.cjs:32:14) {
code: 'ERR_REQUIRE_ESM'
}