1,347 questions
337 votes
9 answers
166k views
Difference between "module.exports" and "exports" in the CommonJs Module System
On this page (http://docs.nodejitsu.com/articles/getting-started/what-is-require), it states that "If you want to set the exports object to a function or a new object, you have to use the module....
-2 votes
1 answer
71 views
ESM & CommonJS Dual Support in an Existing Node.js Project [duplicate]
I'm updating a Node.js project to support both CommonJS and ES Modules (Dual Package). My current issue appears when trying to load the module from the project root using exports field instead of main....
0 votes
0 answers
115 views
Graphql-codegen broken with Node v23
When trying to generate graphql queries automatically for my vite app, I'm encountering this error: 18:02 $ npm run codegen > [email protected] codegen > graphql-codegen /home/...
0 votes
0 answers
21 views
Using ESM plugins in ESLint CommonJS config
So I have an Angular NX Monorepo, which has a base eslint.config.js, and each lib extends the base config in its own config. All configs are CommonJS and use require() syntax. I want to use the simple ...
0 votes
1 answer
116 views
ExperimentalWarning: CommonJS module /app/noop.js is loading ES Module /app/...js using require()
Underneath it also says Support for loading ES Module in require() is an experimental feature and might change at any time
11 votes
3 answers
10k views
Using umd globals with modules in a Typescript project
I am trying to get the Leaflet library to play well with my Typescript project. My project follows the commonJs pattern (imports\exports in my source files), but when I build with webpack, the ...
1 vote
0 answers
97 views
Error: [ERR_REQUIRE_ESM] in Typescript Sequelize
When I try running any command in Sequelize, inside or outside the docker container, that needs the configuration file (In my case, config.mjs), I get this error: Error reading "build/database/...
5 votes
1 answer
6k views
Configure Rollup to add file extensions into import/require statements
I have a hybrid cjs/esm Node package written in Typescript. It consists of, let's say, two files - core.ts and extra.ts and I want to keep them separate. extra.ts imports core.ts (literally import { .....
2 votes
1 answer
9k views
Export assignment cannot be used when targeting ECMAScript modules
I have created a npm project, in which I am using typescript configuration (tsconfig.json). In one .ts file, I have code such as below: export = function loginToLCSteps() { this....
50 votes
2 answers
124k views
Named export 'Types' not found. The requested module 'mongoose' is a CommonJS module, which may not support all module.exports as named exports
I have an express server written in typescript with "module": "es2020" in its tsconfig. I've also developed another es2020 module for my graphql API, still in typescript, and this ...
1 vote
3 answers
3k views
Dynamically load ESM module in CJS package in TypeScript
I am trying to load a single ESM module in my TypeScript CJS project. All examples I find are for JavaScript. // example.ts export const example = async () => { const module = await import("...
0 votes
2 answers
200 views
"name" is not exported by "module" even when using @rollup/plugin-commonjs in vite (rollup) build
I'm migrating a react site from from CRA (webpack) to Vite (Rollup), and despite using the @rollup/plugin-commonjs addin in my vite config, (which did solve all of the name-is-not-exported-by-module ...
1 vote
1 answer
33 views
How do I retain types of namespace over dynamic loading?
I'm building a cross-platform app in Node.js + TypeScript that uses OpenCV. On Windows I use the original opencv4nodejs, and on Linux I use the actively maintained fork @u4/opencv4nodejs. To avoid ...
1 vote
0 answers
118 views
transformMixedEsModules not working for mixed ESM/CommonJS modules
I'm having some confusion when using the rollup plugin commonjs. In my application, some third-party packages in node_modules use CommonJS syntax. By default, I use @rollup/plugin-commonjs to handle ...
0 votes
0 answers
78 views
Vite/Nuxt 3 dev server: "eventemitter3 doesn't provide an export named 'EventEmitter'" but works in production build
i'm building a Nuxt 3 (Vue 3) app using Vite as the dev server. My app uses dependencies like @solana/web3.js and socket.io-client, which internally depend on eventemitter3. when I run the dev server (...