Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
59 views
+50

"[ERR_REQUIRE_ESM]: require() of ES Module" error in TypeScript + Webpack + webpack-node-externals case

Although this error is quite widespread, this solution is technology stack dependent (even with TypeScript/JavaScript various technologies could be used). This question is narrowly specialized on ...
Takeshi Tokugawa YD's user avatar
0 votes
1 answer
43 views

Is there a difference in module creation if I use export * instead of export {Component1, Component2} in my index.ts

I recently ran into a failing test where I received the following error message" TypeError: Cannot redefine property: getCurrentRouteSnapshot I read the following StackOverflow and found this ...
IMeyers20's user avatar
  • 191
1 vote
1 answer
63 views

How to dynamic import chai in CommonJS?

chai latest version 5.1.2 move to ESModule. Is it possible continue use it in CommonJS file? chai is just a dev dependency in my project, used for unit test. I don't want to upgrade my modules to ...
Kerwen's user avatar
  • 552
0 votes
0 answers
17 views

_interopRequireDefault2 is not a function

Environment Operating System: Darwin Node Version: v20.11.0 Nuxt Version: 3.14.159 CLI Version: 3.15.0 Nitro Version: 2.10.4 Package Manager: [email protected] Builder: - User ...
bobrov_site's user avatar
0 votes
0 answers
28 views

how to use ES6 file in CommonJS using Adonisjs

I'm a C++ developer. I barely do any web related stuff. So please bear with me. I'm using adonisjs. Everything is fine. I have a javascript file which works just fine. It does some numerical ...
cauchi's user avatar
  • 1,543
0 votes
1 answer
82 views

Universal way to use CommonJS in Javascript with ESM

ESM is the normalized way for module function in Javascript. But there are many CommonJs package in npm. Vite is good tools for change CommonJs to ESM, I want to use protobufjs in a vue project. The ...
Aklscc's user avatar
  • 13
0 votes
0 answers
63 views

SyntaxError: Unexpected token 'export' from node_modules

I want to use browser-image-hash npm package in a project. For setting up the project I did: npm init -y npx tsc --init npm install browser-image-hash I then added an index.ts file with the ...
10may's user avatar
  • 380
0 votes
0 answers
26 views

CommonJS module loading in Electron

Problem: Loading commonjs module in electron app and using it in the renderer code. import './subc/simplewebrtc.3.1.0.js' import './subc/adapter-8.2.2.js' import './subc/simplewebrtc-mf.js' // Above ...
Shayan C's user avatar
  • 1,580
1 vote
0 answers
71 views

Why is a top-level code executed twice in NodeJs?

I am modifying a project where a file contains some infrastructure variables. I executed code with side effects at the top level, but found that the side effects were repeatedly triggered during ...
bugyaluwang's user avatar
0 votes
0 answers
77 views

How can I import the ESM-only module in my NestJS CommonJS project?

I'm trying to use the strip-ansi package in my NestJS project, which uses ES style imports but compiles to JavaScript using CommonJS. Here is how I use imports in my files: import { Injectable } from '...
vinozganic's user avatar
0 votes
0 answers
42 views

ReferenceError: dirname is not defined in SvelteKit production build using mpd-api

I'm encountering an issue with a SvelteKit application in production. The app uses the mpd-api module in a server-side function to provide Now-Playing data to the client. While it works fine in ...
NotBadri's user avatar
0 votes
1 answer
227 views

"File is a CommonJS module; it may be converted to an ES module." & autocomplete not working

I've looked everywhere and I can't seem to find away to resolve this issue. I can easily hide the error message by adding "javascript.suggestionActions.enabled": false. But that doesn't fix ...
Wall-eee's user avatar
0 votes
0 answers
21 views

Rollup.js ES bundle failing to resolve react-icons/io5 dependency

I'm working on creating an NPM package (for a private company-specific NPM registry) containing a single React component and from searching online on how to do this, I decided to use Rollup.js to ...
Neil Patel's user avatar
2 votes
2 answers
119 views

Why is a TS80005 error showing up in my TS code?

index.ts const utils = require("./utils.ts"); console.log(utils.sqrtRoot("asd")); utils.ts function sqrtRoot(x: number): number { return Math.sqrt(x); } module.exports = { ...
Kishan Kumar's user avatar
1 vote
1 answer
201 views

Issue puppeteer CommonJS/ESM "puppeteer.Locator.race"

We use Chrome recorder and export the recordings as puppeteer Javascript files, which are in CommonJS. They run fine with node. Changing the puppeteer import to ESM, we get the error: TypeError: ...
Fritz Herbers's user avatar
0 votes
0 answers
23 views

Uncaught Reference error: require is not defined [duplicate]

Below code cause this issue return iconLists.reduce((list, name) => { const pL = list; pL[name] = require(`./svg/${name}.svg`) return pL }, {}) } tried different plugins no luck. ...
Aegon's user avatar
  • 17
0 votes
0 answers
39 views

Cannot orchestrate typescript + node + ESNext modules

UPDATE now includes an answer! So I want to publish a typescript module, but I have an either-or problem importing the modules I need or exporting the module correctly. Here is a minimum repro case, ...
Blunt Jackson's user avatar
1 vote
1 answer
657 views

Why won’t TypeScript let me import a type from an ES module into a CommonJS module?

I’m writing a Node.js app in TypeScript. Here’s a simplified version of my files so far: // package.json { "type": "module" } // tsconfig.json { "compilerOptions": { ...
Andrew's user avatar
  • 5,036
2 votes
0 answers
55 views

CommonJS vs. ES Modules: this Behavior with call(null) and call(undefined)

I saved the following code as index.cjs so that node considers it as a CommonJS module. console.log(this); function getThis() {     console.log("this", this); } getThis.call(null); getThis....
Arman Lalani's user avatar
-1 votes
1 answer
517 views

How can I use eslint:recommended and Google in eslint 9 with commonjs syntax?

I have a new project I want to use Eslint9 for. I want a clean setup and therefore utilize the new format. As the project is a WebApp, it's a script/common.js and not a module syntax. I tried to set ...
HOK's user avatar
  • 257
0 votes
0 answers
15 views

Commonjs and ES6. Import doesn't work on module

I'm on react, I have a file I need to run on a command like this "runFunction": "npx ts-node ./src/seedParkStreetSalesData.js" And this is the file /* import { Op } from '...
alexgarciaalcuadrado's user avatar
0 votes
0 answers
136 views

`tsc` to produce CommonJS and ESM versions of my typescript library

I am quite new to JavaScript/Typescript in general and to JavaScript modules in particular. I know there is tons of materials about my question in the web, but after reading for two days I feel I find ...
Bene's user avatar
  • 21
-1 votes
3 answers
314 views

Not able to use CJS(commons) npm package in ESM(type=module) project

I had developed one npm package for my internal use which is written in CommonJS as it uses the express.js so i kept it in common.js but when i try to import that package in my react.js project along ...
dhruvin vaghasiya's user avatar
0 votes
0 answers
22 views

make vscode show error when importing commonjs module incorrectly

I have typescript repo with esm and type=module, so, no commonJS. I need to import a commonJS package and I did something like: import { aFunction } from 'someCommonJSPackage'; vscode is not ...
aperezfals's user avatar
  • 1,379
0 votes
0 answers
695 views

Could not dynamically require

I write electron applications using typescript, vite and react. I also want to use sqlite (the application should run locally). I found a great ORM (Drizzle), but I have a problem with the libSQL ...
GetReady's user avatar
0 votes
1 answer
319 views

Why NodeJS is able to load esm modules without default export for some packages?

When you have an ESM module like this: // greetings.js export const hello = 'hello'; export const hi = 'hi'; and you try to import it using default export: import greatings from './greetings.js'; ...
Sina Sharifzade's user avatar
0 votes
0 answers
152 views

How to named export from CommonJS module with rollup?

I have the following src/infrastructure/db.ts file: @injectable() export class Database { } and src/infrastructure/index.ts: import config from 'config'; export * from "./db" This file is ...
khteh's user avatar
  • 3,832
0 votes
1 answer
302 views

Migrating Angular 13 to Angluar 18

I am using with angular 13 https://github.com/bbc/slayer Its a commonjs lib and has no @types.I Managed to make it work with angular 13 (a while back) but now with the vite compiler I just dont know ...
Brett's user avatar
  • 1,781
0 votes
1 answer
52 views

difference between import and require

// test.js file; let k = 0; let set = () => { k = 1; }; export { k, set }; // test1.js import { k, set } from './test.js'; set(); console.log(k); // --> k = 1; but // test.js let k = 0; ...
Haydar C.'s user avatar
  • 785
0 votes
1 answer
124 views

TypeScript compilation breaks import of my library (package.json exports)

I am writing a JavaScript library that I would like to be importable via script tag, ES6 imports, and traditional (Node) requires, with or without TypeScript or any build systems. I am finding this ...
Jacob Runge's user avatar
0 votes
1 answer
265 views

Angular 15 update CommonJS or AMD dependencies can cause optimization bailouts

So, I upgrated Angular 14 up to 15. my package.json is { "name": "tracker-web-dictionary", "version": "0.0.0", "scripts": { "ng": &...
Anna Korotkova's user avatar
0 votes
0 answers
16 views

Make a CommonJS module in random folder use the node_modules of the main module

I have the following two JS files: /folderA/a.js require('/folderB/b.js'); /folderB/b.js require('ws'); The ws module is located in /folderA/node_modules/ws, hence the b.js fails to find it. I was ...
Dinko Ivanov's user avatar
1 vote
0 answers
124 views

default export - is not a function

I'm currently working in a legacy project that's built using CommonJS. But because I needed to use react-pdf to create PDF files, I had to add .mjs files to my project. This works fine on the dev ...
SaltyPotato's user avatar
0 votes
2 answers
776 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("...
myol's user avatar
  • 9,780
0 votes
1 answer
305 views

Remix (Vite) unable to import from @apollo/client into .tsx files issue

I have the following root.tsx file: import { ApolloClient, createHttpLink, InMemoryCache, ApolloProvider } from "@apollo/client"; import { LinksFunction } from "@remix-run/node"; ...
starter_dev's user avatar
1 vote
0 answers
75 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/...
Giovani Souza Kill StevePlays's user avatar
0 votes
1 answer
244 views

Create declaration file for third party library as CJS

I am using a third party CommonJS (CJS) library without types. My project is CJS with TypeScript. The importation works just fine (imports are transpiled to requires) if I disable errors using ...
myol's user avatar
  • 9,780
0 votes
0 answers
77 views

NestJS project wont resolve workspace dependency

I have an npm workspace setup as below apps node_modules packages tsconfig.json global-teardown.ts package.json services root package....
Victordanny's user avatar
0 votes
0 answers
142 views

Use require in vue3 project with bun - not working: require is not defined

I have a question about using a common js package in a new vue3 project. const io = require('socket.io') with an older socket.io version (v2). However, it does not really matter which package I am ...
Merc's user avatar
  • 4,542
1 vote
1 answer
1k views

How to compile a project to ESM + CJS and have one file different?

I want to compile my TS project to both ESM and CJS. I've set up two tsconfig files to do that and so on. One of the files tries to conditionally import packages, which is something that has to be ...
GregRos's user avatar
  • 9,073
0 votes
0 answers
22 views

how do I create code transformer for parsing customized extension like JSX?

i am developing new web framework library like react, to deploy as npm package. its name is actually 'fluid', so extension is .fluid. so i had to test with jest, but it can't compile .test.fluid file ...
shyunku's user avatar
0 votes
0 answers
104 views

serverless-offline module --> Cannot use import statement outside a module

I am currently developing a simple lambda function using node.js with serverless.yml templates. My project is using typescript and tsconfig is set to ESNext target version along with ESnext module as ...
zhouf's user avatar
  • 25
0 votes
2 answers
283 views

TypeError: Cannot convert object to primitive value when trying to use template literal in require(`${some_var_string}`)

Try to use lib "react-inlinesvg" in Vite. i have such code: <SVG src={require(`../../../assets/icons/icon/logo_${themeProp}_full.svg`)} />; and in result i have: react-inlinesvg.js?v=...
Evhenii's user avatar
  • 47
2 votes
0 answers
195 views

How do you combine subpath exports, environment conditional exports, and module system conditional exports in the same package.json?

When publishing an NPM package, there are three distinct types of export that you can specify in a package.json file. Subpath Exports This allows you to export multiple ‘indexes’ from a single ...
steveluscher's user avatar
  • 4,217
0 votes
0 answers
85 views

How to compile typescript to use CommonJS and import/export?

For example, I have an index.ts file in which a function that returns the sum of two numbers is exported via export. And also the test.js file which imports the function from the already compiled ...
PinBIb's user avatar
  • 1
0 votes
0 answers
909 views

How to build TypeScript/MJS package compatible with NodeJs?

I try to write a TypeScript/MJS package for NodeJS (v20) application, but face errors like : "exports is not defined in ES module scope" or also "Unexpected token 'export'" or &...
serge's user avatar
  • 15.1k
2 votes
2 answers
964 views

Trying to import KcAdminClient

I’m trying to use the Keycloak Admin Client library in my Nodejs (Typescript) application, but there's a problem about ES6/CommonJs stuff, which I never really understood (import vs require and mixing ...
Lucio Crusca's user avatar
  • 1,507
0 votes
0 answers
87 views

Cannot import ESM modules when modifying require.extensions

TL;DR How to require (or import) Native ESM modules while using a require hook like require.extensions. Note: I do know that require.extensions is deprecated and is not recommended to modify, but as ...
devjiwonchoi's user avatar
-2 votes
1 answer
2k views

Import ESM libraries into commonjs project Error [ERR_REQUIRE_ESM]: require() of ES Module -

Problem I have a 'commonjs' typescript project and I need to add several npm dependencies that are ESM packages. I can't move my project from type: 'commonjs' to type: 'module at the moment and I am ...
BSimpson's user avatar
  • 345
0 votes
1 answer
54 views

Exposed and private/local members in CommonJS modules

I was testing this framework and got these issues, idk why they happen and couldn't find the answer neither in Node.js docs nor in global search. init.js const { f1, v1, v2, f2 } = require('./1.js') ...
ilias's user avatar
  • 334

1
2 3 4 5
27