Questions tagged [esmodules]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
48 views

Cannot call other functions in the same Typescript file

I'm importing function from a Typescript file: import { myExportedFunction } from '../utils/myFile'; The myExportedFunction function calls a non-exported function in the same file: const ...
syydi's user avatar
  • 161
0 votes
1 answer
19 views

website like a paytm what is more suitable common JS or ESM

I'm thinking of making a website that works like Paytm and they have similar features what are we going to use which one is more suitable, a common JS or ES module and with the reasons what is the ...
user22867147's user avatar
0 votes
0 answers
38 views

import enviroment variables in js file in assets folder in Angular project

I created a mobile-device.js file into assets/mobile folder in my Angular project, then I added the file path in the scripts array in angular.json file like this: "scripts": [ "...
Trispo's user avatar
  • 41
-1 votes
0 answers
55 views

Require in ESM not supported

I have a problem. I integrated the storybook in our project with Next JS, Docker, yarn v1.22.19. I know about it, it is a very old story book, but I don't think that's the problem. After that I used ...
Anar Guliev's user avatar
-3 votes
1 answer
118 views

How to import an es module in Node without an extension

I've heard that when importing ES modules, you're supposed to include a file extension. However, I came across some Node projects that import ES modules without an extension, like in this example. I'm ...
yuanzui_cf's user avatar
0 votes
1 answer
49 views

Direct umd module import returns different result than aliased import

In Vite/Vue3 app I import two identical umd.js files: One is in node_modules/foo/bar/dist/foobar.umd.js (and imported with alias @foo = node_modules/@foo). Second .umd.js file is in <root dir>/...
van_folmert's user avatar
  • 4,277
0 votes
0 answers
31 views

Can the npm Webtorrent (v2.1.27) package still run inside node (using typescript)?

I want to use the webtorrent package inside an Express application in typescript, but no matter how I configure my tsconfig file I keep getting compilation errors Error [ERR_REQUIRE_ESM]: require() of ...
PiwiTheKiwi's user avatar
0 votes
1 answer
53 views

Express App - Creating a Nested Route with ES Modules

I've followed a tutorial to create an Express app with an API. With the tutorial completed, I am now trying to convert it from CommonJS to ES Modules. I tried looking through resources like the ...
Marina's user avatar
  • 3
0 votes
1 answer
37 views

Why doesn't the VS Code JS Debugger pause on uncaught exceptions in ES modules in NodeJS?

This recently became an issue and I'm not sure what triggered it. As soon as the debugger encounter's an error, it exits and prints: Process exited with code 1 Which isn't very helpful at all. I've ...
hedgehog90's user avatar
  • 1,442
0 votes
0 answers
15 views

Using dojo (legacy aka dojotoolkit) in a new vite application

We have a legacy application written in TypeScript and Knockout that has sporadic use of dojo 1.x (on, when, Evented, store/Memory, Deferreds) that we are slowly converting to React. We have used the ...
Eirik H's user avatar
  • 664
0 votes
0 answers
234 views

Include external ES modules in the bundle

I'm getting an error when running esbuild complaining: You can mark the path "hiom" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in ...
Jan Vladimir Mostert's user avatar
0 votes
0 answers
96 views

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported in node_modules

I'm creating my web program with next.js. After upgraded node version, this error occured. Error [ERR_REQUIRE_ESM]: require() of ES Module ~ from ~ not supported. This error happens my node_modules ...
Daae Kim's user avatar
0 votes
0 answers
11 views

Does webpack4 support export esmodule format file?

I know webpack 4 is very old as it's published at 2018. But in my project it's webpack4 still. And i want to export esmodule format file. So i can use to load javascript files. And my babel config is ...
chaser zhang's user avatar
0 votes
0 answers
78 views

Import .docx files as an es module in javascript

Is there anyway to import .docx files as ES modules? Like this: import template from "@lib/assets/template.docx" I've searched a lot for the past months and I couldn't get a direct answer. ...
Jhon Philip Guiang's user avatar
0 votes
1 answer
1k views

How to get vitest working with require of ES module

Trying to migrate some old TypeScript code from CRA to Vite, and getting stuck on a problem with Vitest. The project has dependencies like this: my-project (ESM) depends on: lib1 (CJS) depends ...
usethe4ce's user avatar
  • 23.3k
0 votes
0 answers
114 views

Webpack tree-shaking removes side-effects code

I was testing out webpack tree-shaking behavior. As per the docs, any code that contains side-effects can be mentioned in the sideEffects property of package.json to inform webpack not to eliminate ...
Arjun Mudhaliyar's user avatar
1 vote
0 answers
47 views

Typescript: Disallow directory imports

I'm using typescript with https://npm.im/tsm in development and for builds I would love to stick with the Node LTS module resolution algorithm [at time of writing] that does not allow directory ...
JaKXz's user avatar
  • 1,675
0 votes
0 answers
19 views

Getting CORS error while working with OpenLayers v7.5.2 [duplicate]

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///C:/Users/kalam/Documents/my-ol-app/main.js. (Reason: CORS request not http). Module source URI ...
Ekta Kalamkar's user avatar
0 votes
1 answer
54 views

how to import custom js modules using es module imports

When using the commonjs I used to import custom modules like this:- const date = require(__dirname + "/date.js"); after switching to es module type I can no longer use the __dirname without ...
G Ajeet's user avatar
  • 27
0 votes
2 answers
49 views

NodeJS - How do I call separate imports based on 'if' condition for ES Modules?

Followed a tutorial that uses CommonJS to export/require different keys based on the environment. How do I get it to work with ES Modules import/export? This was the code he used: if (process.env....
Meaetin's user avatar
0 votes
0 answers
49 views

Trouble with ES Modules when using Swiper.js in an Nx Monorepo with Next.js

In my current project, which utilizes the Nx monorepo environment combined with Next.js, I've encountered an issue related to ES modules. The problem is specifically tied to the Swiper.js library. ...
DevOverflow's user avatar
  • 1,223
1 vote
1 answer
62 views

After switching to ESM import in .ts files no longer supports files without extension

After switching from CommonJS to esnext module, import of other .ts files from .ts file is no longer possible. My getButton.ts imports this: import { Button } from "../../../objects/Button"; ...
John's user avatar
  • 249
0 votes
1 answer
513 views

Named export 'YoutubeVue3' not found. The requested module is a CommonJS module, which may not support all module.exports as named exports

I have a problem with youtube-vue3 plugin that I use in Nuxt3 project. It causes me problem with prerender on yarn generate. Here is how it looks: <Youtube :width="width" ...
E. Mammadli's user avatar
-2 votes
1 answer
42 views

Why import can be used in this commonjs module?

Code is here: https://github.com/timewalker08/wechaty-test/tree/master According to nodejs document: If the nearest parent package.json lacks a "type" field, or contains "type": &...
timewalker's user avatar
0 votes
1 answer
78 views

What is [ERR_PACKAGE_PATH_NOT_EXPORTED] exactly referring to in this case?

I am trying to serve the following http_server.js files on my virtual machine that I have set it up on digitalocean. Why am I getting this error message? this is my http_server.js file: // Import ...
Sar's user avatar
  • 1
1 vote
1 answer
122 views

How can I solve Unexpected Token 'export' for Jest Testing [closed]

I am writing tests for a React App. While running my tests, I'm getting this error.Error Message Grid is being exported from "node_modules/gridjs/dist/index.d.ts" Export file Here is my jest....
Nick2Legit's user avatar
0 votes
0 answers
77 views

Is there any way to get Jest to handle importing libraries with esmodules?

Historically I've just used the transformIgnorePatterns option in Jest to convert esmodule libraries from esmodules to commonjs: module.exports = { transformIgnorePatterns: [ '<rootDir&...
craigmiller160's user avatar
2 votes
0 answers
259 views

VITE Buildiing phase: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'vite-plugin-commonjs'

I'm trying to dpeloy my first vite project but i'm getting the following error: 9:32:18 AM: $ npm run build 9:32:18 AM: > [email protected] build 9:32:18 AM: > vite build 9:32:18 AM: ...
Joao Ghabriel's user avatar
0 votes
0 answers
36 views

failed to load resources or couldn't find the module. importing images in vuejs component

I'm trying to import my images, but i get couldn't find module or failed to load resources. I've used the require function, but it doesn't work too! `<template> <div> <div v-for=&...
soroush mohamadi's user avatar
1 vote
1 answer
194 views

ESmodules: The requested module '****' does not provide an export named '****'

Newbie question here. I have this problem using ESmodules. SyntaxError: The requested module './esModules.js' does not provide an export named 'add'. I do have the "Type": "modules"...
Fonsecar's user avatar
1 vote
0 answers
154 views

Typescript add custom type definitions for esm library from commonjs project

When using commonjs libraries it is possible to extend/overwrite their type, for example: declare module 'ramda' { function path<T>(path: Path, obj: any): T; } But how can we do this with esm ...
valerii15298's user avatar
-1 votes
1 answer
154 views

Qwik errror during build. ReferenceError: exports is not defined in ES module scope

How to solve this qwik framework error during build a static site: ReferenceError: exports is not defined in ES module scope at file:///media/oem/MyFiles/8_DEVELOPMENT/nexasoft/server/@qwik-...
Maik col's user avatar
0 votes
2 answers
1k views

How to solve " [ERR_REQUIRE_ESM]: require() of ES Module" for Webpack case?

I tried to import the w3c-html-validator but got the error Error [ERR_REQUIRE_ESM]: require() of ES Module D:(...)\node_m odules\w3c-html-validator\node_modules\chalk\source\index.js from D:(...)\...
Takeshi Tokugawa YD's user avatar
0 votes
0 answers
165 views

How to create project in TypeScript for NodeJS 16 that runs as ES Module?

I have a NodeJS project written in TypeScript and I want to change it to generate ES Module so I can use my NodeJS shell with an import statement: What I did was adding "type": "module&...
jcubic's user avatar
  • 63.1k
0 votes
0 answers
18 views

Problems importing custom node-modules library

I'm developing a library for a Typescript codebase that I want to install via npm, but I am not able to import exported members as I would expect. My primary code is Typescript running on v4.7.4. My ...
flimsy's user avatar
  • 204
1 vote
0 answers
28 views

Is javascript module for browser or node

Is there a certain way to tell if a javascript module or library is meant to be used on the browser or on node/deno environment? I know that library authors can use the browser field in package.json ...
dinika saxena's user avatar
1 vote
2 answers
134 views

Why is importing an icon named ImportExport breaking other dependencies?

I added a Material-UI icon to one of my react components like so: import { ImportExport } from '@material-ui/icons'; Thereafter, on my production site (but not my localhost dev server), I started ...
temporary_user_name's user avatar
0 votes
0 answers
314 views

NPM: sub-dependency of local dependency has require() in ES module and causes runtime error in production build

I have a Vue3 app under Vite. It's working marvellously in dev, but after adding a dependency, the production build falls over at runtime with require() is not defined. Grubbing down into node_modules,...
bbsimonbb's user avatar
  • 27.5k
0 votes
1 answer
1k views

AWS CDK NodejsFunction: import a module exported as "export ="

Is there any way to use modules (e.g. sharp) exported as export = someModule in a Lambda function defined using NodejsFunction in the aws-cdk-lib? The require statement(const xxx = require('module')) ...
kusumoto_teruya's user avatar
0 votes
2 answers
843 views

Import Map on Firefox v107 with `es-module-shims` polyfill is not working for dynamic import

I'm using Import Maps on my website which (according to caniuse.com) aren't supported on Firefox v107 or the latest (non-TP) version of Safari. I thought that the es-module-shims polyfill library ...
Arcanist's user avatar
0 votes
1 answer
190 views

Can webpack generate a module with exports?

I was able to create a webpack config to bundle few modules. The generated bundle looks as follows: /* harmony default export */ const subscriptions = ({ ... // my stuff /******/ })() ; I'd like to ...
4ntoine's user avatar
  • 20k
0 votes
1 answer
87 views

How to provide test ESModule implementation in mocha test?

I have a mocha test which tests my code. My code uses another "core" npm package (which uses CommonJS modules). One of "core" the files ("synchronizer.js" file) requires &...
4ntoine's user avatar
  • 20k
1 vote
2 answers
560 views

Why does webpack use script tag for dynamic import when dynamic "import()" is already supported?

Lately I've been deep diving more about JS modules, Webpack, the difference between ES modules and CommonJS, and I came across the dynamic import topic. I was curious on how Webpack converts the ...
hskris's user avatar
  • 111
0 votes
1 answer
700 views

Export all files from a folder in es module

I have the following script which is attempted at exporting every single file from a particular folder, but I'm stucked at the export part of it. Below is what I've attempted: index.js function ...
ololo's user avatar
  • 1,474
1 vote
0 answers
95 views

How to divide gulp tasks into multiple .ts files?

I've tried to setup Gulpfile configuration only with Typescript. Created in project's root folder named gulpfile.ts with index.ts: import { task } from 'gulp'; import { clearBuild } from './tasks/...
Evgeniy Reut's user avatar
0 votes
1 answer
85 views

Destructured imports vs namespace in react libraries using typescript

My question is : is there any consequences in performance if using for example: import * as Reanimated from 'react-native-reanimated' Instead of : import { useSharedValue, useAnimatedStyle, ...
Djakarta_zero's user avatar
2 votes
0 answers
380 views

Monorepo Typescript how to build package together?

I have Pacakage 'A' And app 'B' 'Package A' index.ts export default "foo" A's package.json main: index.ts types: index.ts A's tsconfig.json "module": "commonjs", 'APP ...
MINJA KIM's user avatar
  • 888
1 vote
0 answers
241 views

Different behaviour with Mocha between `pnpm ln -g <pkg>` and `pnpm add github:<pkg>`

Some quite complex problem I am having here that I can't find a solution : Context I would like to use the ts version of the library algebrite : https://github.com/davidedc/Algebrite But I required ...
hl037_'s user avatar
  • 3,597
1 vote
0 answers
314 views

How to print what files are transformed by babel or babel plugin?

I am writing babel and jest configuration that should transform one of node_modules. At the moment is does not work and I would like to know if the error that I am getting is because the files are not ...
Žilvinas Rudžionis's user avatar
1 vote
1 answer
102 views

Nodejs + TS CommonJS vs Module issue for Inquirer package

When i imported inquirer i have started getting errors about CommonJS and Modules errors. So this current one suggesting my to use dynamic imports const inquirer = await import('inquirer'); then i ...
Marius's user avatar
  • 1,773