The standard module system for JavaScript, introduced in ECMAScript 6 (2015).
Questions tagged [es6-modules]
2668 questions
53
votes
6 answers
Is there any way to mock private functions with Jest?
The ES6 module that I want to test looks as follows:
function privateFunction() {
...
}
export function publicFunction() {
... does something ...
privateFunction()
... does something else ...
}
I am using JEST for my unit tests and I am…

matteo
- 1,635
- 1
- 15
- 26
51
votes
4 answers
ts-jest does not recognize es6 imports
I'm adding typescript support to a react codebase, and while the app is working ok, jest tests are failing all over the place, apparently not recognizing something about es6 syntax.
We're using ts-jest for this. Below is the error message I'm…

Ernesto
- 3,837
- 6
- 35
- 56
50
votes
19 answers
ExpressJs is return error `ERR_MODULE_NOT_FOUND` if I import the file without `js` extension
I build a expressJs app by ES6 and I got the below error:
(node:4132) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/run_main.js:54
internalBinding('errors').triggerUncaughtException(
…

Mukesh Singh Thakur
- 1,335
- 2
- 10
- 23
49
votes
3 answers
'ReferenceError: jest is not defined' when running unit test
I'm in the early stages of a new app that so far just uses vanilla JS. I'm trying to use ES6 modules for my Jest unit tests, so I followed the 2020 updated instructions on making this possible.
However, after following those instructions, I get the…

Eric
- 1,167
- 3
- 11
- 18
49
votes
2 answers
Do require.resolve for ES modules
I need to resolve ES modules, imported via static import or function-like dynamic import, in a way similar to how CJS modules in node.js can be resolved using require.resolve(). Does anything like that exist for ES modules?
For example, if a Vue…

Dmitry Sharshakov
- 678
- 1
- 6
- 7
48
votes
8 answers
webpack imported module is not a constructor
I created a small JS module which I intend to make an npm package, but for now is just on GitHub. This module is written in ES6 and SCSS, and is thus relying on webpack and babel for transpilation.
To test it, I created a separate project with a…

Liran H
- 9,143
- 7
- 39
- 52
47
votes
5 answers
Which browsers support import and export syntax for ECMAScript 6?
I am currently writing a web application using the MEAN Stack, and am attempting to write code in ECMAScript 6 JavaScript; however, I am getting errors in both Chrome and Firefox when using import and export syntax. Are there currently any browsers…

Gregory R.
- 1,815
- 1
- 20
- 32
46
votes
3 answers
Does ES6 import/export need ".js" extension?
I installed chrome beta - Version 60.0.3112.24 (Official Build) beta (64-bit)
In chrome://flags/ I enabled 'Experimental Web Platform features' (see https://jakearchibald.com/2017/es-modules-in-browsers)
I then tried: