Questions tagged [es6-modules]

The standard module system for JavaScript, introduced in ECMAScript 6 (2015).

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

JavaScript Es6 vs Es7 - What Difference [closed]

Can anyone tell me Difference between these two versions and also tell any depreciation happened between them, New modules،new concepts.Any impact on JavaScript websites or create a bug that overnight ...
Muhammad Hassan Saeed's user avatar
1 vote
2 answers
41 views

why the testvar ??= "default"; still yield testvar is not defined?

I have something in my html: <script> testvar = "mytest"; </script> <script src="index.js" type="module"/> Since some html might not declare the ...
Wang's user avatar
  • 7,481
0 votes
1 answer
20 views

Is there vue devtools as ES module, or is there pinia prod ES module without dependencies?

I try to use pinia 2.1.7 as ES module, together with Vue 3.3.8. So: <script type="module" src="./js/lib/vue-3.3.8.esm-browser.js"></script> <script type="module&...
peter_the_oak's user avatar
0 votes
0 answers
30 views

Why can I import a script file from a local directory but I can't when the type is a module? [duplicate]

Let's say you create a project folder named 'project' in your desktop and inside of it a simple index.html file. Now, you want to create a script and so to not polute your index.html, you code your ...
Gabriel Andrade's user avatar
0 votes
0 answers
14 views

Executing jest tests in angular with a .mjs library

I have an Angular 17 project and want to run my tests with jest. However, when executing them I receive the error SyntaxError: Identifier 'exports' has already been declared for files in my ...
StNimmerlein's user avatar
0 votes
0 answers
8 views

extending js (maplibregl) library with new namesapce

I want to create a new js library on top of maplibregljs. My newLibrary.js import maplibreGl from './lib/maplibre-gl.js' class MyNewMap extends maplibreGl{ //my custom constructor and features } ...
Koustav Ray's user avatar
  • 1,112
-3 votes
0 answers
85 views

Import behaviour with Typescript [closed]

How are we able to import Request, Response, Express interface from express import express, {Express, Request, Response} from 'express'; Checked the types declaration file we are only exporting ...
Shubham Dogra's user avatar
1 vote
0 answers
44 views

Firefox import assertions not currently supported

Firefox throws and unsupported error on: import sheet from '/Vanilla/ScrollGrid.css' assert {type: 'css'}; Can I use says Unsupported. and "Missing )" error after: myCSSMod = await import(...
McMurphy's user avatar
  • 1,289
0 votes
0 answers
23 views

What are the ways a default export can be given an implicit name?

Default exports don't have an enforced name but an unnamed default export, export default 'foo'; can be named implicitly like so: const Foo = 'foo'; export default Foo; Named functions are also ...
Arnaldur's user avatar
0 votes
0 answers
20 views

Remove css/html from the bundle after it has been required and processed by webpack

I am developing one node package myself to be able to publish it to node registry and i am using webpack for bundling using ES-6 syntax. I am using css-loader in modules inside rules configuration ...
Shashank Bhatt's user avatar
1 vote
1 answer
37 views

Javascript Importing Modules And Using Them in HTML Document

The problem I have been having is that I cannot get imported modules to work together in vanilla Javascript. Here's my project structure: > toplevel > index.html > main.css > main.js > ...
8SIXSector's user avatar
1 vote
1 answer
85 views

Jest mock an ES module imported by an http server controller

I have a basic express server that I test with Jest and Supertest. I am trying to mock an ES module that is imported by a controller. Testing works fine, but I couldn't make the mocking work. Here are ...
Yılmaz Kasap's user avatar
0 votes
1 answer
9 views

how to test @mdx-js/mdx with jest (transformIgnorePatterns not working on 'develop' module)

My ultimate goal is to be able to write tests in Jest that can import from @mdx-js/mdx, which is an ESM module, and since the library package under development is configured for commonsjs, I am using ...
drkstr101's user avatar
  • 750
0 votes
0 answers
19 views

Local ESM delivery like JSDelivr

I want to setup my local apache delivery the way like jsdelivr.com? Why? Cause once in a while jsdelivr is down and my site can't load. And I'd want to avoid suck situations. For instance, I use ...
user2516873's user avatar
1 vote
0 answers
44 views

Mocking a function in Jest for express app using ES6

I have a file 'userServices.js' that performs all DB-related actions. I want to mock this function to throw an error to test some other function. The behavior of the mocked function will be different ...
Apeksha Joshi's user avatar
1 vote
0 answers
22 views

How to inject jQuery to a plugin within a ESM

My code is failing because a plugin is expecting a jQuery object, but I'm not sure how to pass it in. I'm using modules (and importmap), but the javascript plugin isn't a module. In webpack, i set ...
Tac Tacelosky's user avatar
0 votes
1 answer
14 views

Getting Error [ERR_REQUIRE_ESM] for connect-redis 7.0.1

Node version: 16.20.2 connect-redis version: 7.0.1 esm version: 3.2.25 redis version: 3.0.2 express-session version: 1.17.3 I am getting ERR_REQUIRE_ESM error for connect-redisin my node app. I have ...
Md. Nazmul Haque Sarker's user avatar
0 votes
1 answer
62 views

How to use ES6 import in worker thread in Node.js?

How to use ES6 import in worker thread? I'm trying to utilize ES6 import syntax in a worker thread in a Node.js environment. However, I'm encountering issues with the import statement. Here's a ...
Amitprj's user avatar
1 vote
0 answers
32 views

Material styles cannot be loaded properly when building design system package

In our company, we are trying to build our design system as a package, in order to install it in several of our projects. Building the package works fine, but once we install it and import the theme ...
Antonio Gamiz Delgado's user avatar
0 votes
0 answers
46 views

Vue as ES Module Build loses reactivity when I build component library using vite

I am currently working on a project and want to create several components, build them via vite and use them in another project using the Vue CDN hosted standalone version. As mentioned on the website, ...
Peter's user avatar
  • 101
0 votes
0 answers
31 views

extension error import js in a ts file typescript jest

I'm importing app.js inside a .test.ts file when i run npm test i received the error my import import { buildApp } from '../../../src/app.js'; ERROR Cannot find module '../../../src/app.js' from '...
Jubileu's user avatar
0 votes
1 answer
23 views

Mocha: tests cannot find module

I have a very simple unit test that starts in these lines: import {SOUTH_EVENTS_ENUM, SouthEventsManager} from "@app/common/south_events_manager"; import {expect} from "chai"; ...
CrazySynthax's user avatar
0 votes
2 answers
73 views

How to conditionally modify exports from an ES6 Javascript module

I'm wondering if it's possible to somehow still access the module exports of an ES6 module from within the module, like you do in CommonJS with module.exports. For clarity, I have a js module (Config....
Morgan's user avatar
  • 1,777
0 votes
1 answer
42 views

How to properly build a design system using material ui

in our company we are trying to build our design system as a package, in order to install it in several of our projects. Building the package works fine, but once we install it and import something ...
Antonio Gamiz Delgado's user avatar
0 votes
0 answers
49 views

how to make NestJS with nx work using ESM

this is example with pure nestjs working fine https://github.com/robertIsaac/nest-esm this is example with nestjs with nx not working https://github.com/robertIsaac/nx-nest-esm I already opened an ...
Robert's user avatar
  • 2,457
0 votes
0 answers
18 views

How to load browser.esm.js modules in Nuxt 2?

I am getting the following errors when trying to import @thirdweb-dev/wallets module in a Nuxt 2 project: ERROR in ./node_modules/@thirdweb-dev/sdk/dist/marketplace-auction-3488e43b.browser.esm.js ...
Falcon Stakepool's user avatar
0 votes
0 answers
66 views

Vite build with dynamic imports of Vue components

I have a project built with Vite that dynamically imports Vue components (via async import(filename + '.js')) that are not known at build time. Those vue components depend on vue, and are built with ...
Pez Cuckow's user avatar
  • 14.1k
0 votes
0 answers
30 views

Can't mock imported function in ESM Modules mocha

So I've been trying to mock an imported function for a file that uses external calls to DB, redis, and etc. So I can isolate only the methods of a class that uses that function. In production we are ...
Jay's user avatar
  • 29
0 votes
0 answers
17 views

namespace gsap / Vite Template

I am working on a Vite / JavaScript / Webflow template so it's easier to use JavaScript inside Webflow, and of course GSAP. I have GSAP as a dependency (thank you GS 😍), but when trying to call gsap ...
milkogr's user avatar
2 votes
0 answers
144 views

NPM package with exports won't load in typescript

Our library needs to work both for projects using ESM modules and CommonJS. Therefore we built it with 3 different configurations: ESM, node16, and types. This setup works for JavaScript projects with ...
Arnold Daniels's user avatar
0 votes
0 answers
26 views

Trying to load Angular from Rails - "cannot use import statement outside a module"

I'm on a team that maintains a rather creaky old web application. The backend is in Rails; the frontend is based on Rails but in practice is mostly AngularJS. The project I'm trying to do now is to ...
Luke Bretscher's user avatar
0 votes
1 answer
38 views

Unable to use MJS files on older web hosting platform

I am currently migrating a website from a new platform to a very old one. The older platform does not currently serve MJS files as the expected "application/javascript"/"application/x-...
coolcat99's user avatar
0 votes
0 answers
38 views

Using ES Module style dependencies in Electron 27

I am developing an desktop application with vanilla JavaScript under Electron. I had not configured the packaging workflow like Webpack for may project. Now I am intending to use some third party ...
Camille's user avatar
1 vote
1 answer
55 views

How do I disable ES Module Error's in VSCode?

I have recently made the switch to use Bun as my JS Runtime of choice, and in the switch the relevance of ES Modules vs CommonJS became a moot point because Bun doesn't acknowledge either and it all ...
Jackson Roberts's user avatar
0 votes
2 answers
33 views

The module / DOMContentLoaded event conundrum [closed]

I used to have a js script which is imported in html as type text/javascript. Let's call it main.js I used a DOMContentLoaded event listener, so that as the page was loaded, we would run the script. ...
An old man in the sea.'s user avatar
0 votes
2 answers
93 views

How to use Shadow Dom with Javascript and CSS modules

EDIT 1 Thanks very much @Danny for the very useful answer. I guess my question has more to do with CSS sope and encapsulation. If I import a CSS StyleSheet into a module then I don't want that ...
McMurphy's user avatar
  • 1,289
0 votes
1 answer
399 views

Node 20.9.0 LTS: How to run TypeScript with ts-node with esm support?

I have upgraded my nodejs version from 18 to 20.9.0 LTS. I have a project with typescript, express and node. These are the package.json: { "name": "myproject", "version&...
Muminur Rahman's user avatar
2 votes
0 answers
38 views

What's the difference between direct assignment to `exports` and `Object.assign(exports, ...)`? [duplicate]

This is Node.js 18.17.1. Here's my CommonJS module, module1.cjs: exports.a = 67 Object.assign(exports, { b: 68 }) console.log(exports) console.log(Object.getOwnPropertyDescriptor(exports, 'a')) ...
s100's user avatar
  • 21
0 votes
0 answers
22 views

Performing unit testing in a react app | Problem with ECMA modules

I have this simple unit test: import { setPlayers, playersSlice } from "../../redux/slices/playersSlice"; import { players } from "../sampleData"; describe("players reducer&...
AG_HIHI's user avatar
  • 1,743
0 votes
0 answers
127 views

Can't Use JS Modules: Expected a JavaScript module script but the server responded with a MIME type of "text/html"

everyone. I'm really new to Javascript — just starting to learn, really. I've got a simple HTML file I want to run below. <!DOCTYPE html> <html> <head> <script type=&...
Ethan Edelen's user avatar
0 votes
1 answer
22 views

How To Import JS Code and Evaluate in Importing JS file

Uning just ES6/Modules... I am trying to import a js file that has an object of content with variables that are referenced in the importing js file. I am getting Uncaught ReferenceError: params is not ...
RooksStrife's user avatar
  • 1,657
0 votes
0 answers
108 views

Named export 'xxx' not found. The requested module 'xxx' is a CommonJS module

After I changed the project to esm by add loader NODE_OPTIONS='--loader ts-node/esm' gulp build like this, build the typescript project, shows error: > [email protected] build > NODE_OPTIONS='--...
Dolphin's user avatar
  • 31.1k
0 votes
1 answer
49 views

How to mock node-postgres in vitest

I am trying to mock node-postgres in vitest with esm. But I am running into different problems. When I am using the Pool class in my function: import {Pool} from 'pg'; ... const pool = new Pool({...
Florat's user avatar
  • 141
0 votes
0 answers
15 views

ERR_REQUIRE_ESM when using nanoid

I am working on a URL shortener using Express and Typescript, and I use nanoid to generate the url ids. It is giving me ERR_REQUIRE_ESM error, specifically: Error [ERR_REQUIRE_ESM]: require() of ES ...
bubbles's user avatar
0 votes
0 answers
30 views

rollup hangs while building monorepo packages

I am using version 4.50 of Rollup and it hangs (never stops) while building SOMETIMES (~50%), but NOT always. ~50% of the time it builds all my packages quickly. The main things I think might be ...
cyrf's user avatar
  • 5,197
0 votes
0 answers
9 views

Mocha --file with mochaHooks works on CLI but not as file property in .mocharch.json

In package.json the following script works perfectly for running my mocha tests without any issues. This includes specifying my implementation of a global beforeAll hook via -file src/tests/...
MarkE's user avatar
  • 140
0 votes
1 answer
42 views

Unable to deploy a .mjs file using CDK

I'm trying to create a Nodejs Lambda project locally in vscode, which I'm going to deploy using CDK. I start by running cdk init app --language javascript At some point in my development I'm going to ...
Nick Wright's user avatar
1 vote
1 answer
49 views

Can import all THREE.js post processing modules as ES6 modules except OutputPass

I am trying to replicate this example but with modules imported from CDN. With the following import map: <script async src="https://unpkg.com/es-[email protected]/dist/es-module-shims.js"...
Mr. Developerdude's user avatar
2 votes
1 answer
58 views

Is there a way to import a non-module variable in (browser) ES6 module?

This is for browser Javascript. Assuming I have an external Javascript library: // feature.js var Feature = { /* ... */ } Normally you refer to the file in your HTML and you get a Feature variable in ...
Luke Vo's user avatar
  • 18.6k
-4 votes
1 answer
219 views

What is the Universal Module Definition (UMD)?

I've found the(?) github repository for UMD and it comes with this description (emphasis mine): UMD (Universal Module Definition) patterns for JavaScript modules that work everywhere. ... This ...
Daniel Kaplan's user avatar

1
2 3 4 5
55