es6-modules Questions
7
Solved
I am moving an Express app across from CommonJS require syntax to the ES6 module import syntax. This is fine until I try and use dotenv to load my environment variables and every time I try to acce...
Brnaba asked 31/10, 2020 at 10:46
1
I am running vitest runner. Then I see that someone probably vitest is generating from my .ts files some .js files:
The error message I get seems to be originating from the uiElementsCreator.test....
Entropy asked 21/2 at 16:44
5
Node.js 16.14.2, npm 8.19.2.
I am trying to run a simple Node.js script that imports OrbitDB. Here is the script:
hello_orbitdb.js
// import the package
const OrbitDB = require('orbit-db');
Here i...
Pogue asked 23/10, 2022 at 15:59
1
I have a Node.js project whose modules are imported in the Common.JS way using require. However, the need arose to import a package that is ESM only.
One way to use ESM import from in my project wa...
Hulbert asked 19/7, 2022 at 22:59
2
Solved
I'm determined to find a way to do this. Here's why:
I'm writing tests for .js files which are bundled with webpack for a browser client.
I would like to run these tests in nodejs. There is a "...
Tradeswoman asked 25/7, 2022 at 1:48
4
Solved
I recently read the following in Kyle Simpson's You Don't Know JS: ES6
"[ES6 modules export] actual bindings (almost like pointers) to the identifiers in your inner module definition."
My confusi...
Gemoets asked 31/8, 2016 at 22:6
4
I'd like to make a Javascript file that
exports its content (e.g. a class) if it can export (e.g. it has been loaded with <script type="module">)
and otherwise, assigns its content...
Paella asked 23/1, 2018 at 8:14
4
Solved
Let's say you're developing a polyfill and don't want to shim a class if it already exists in the browser. How can this be done in ES6? The following is not valid because exports is not a statement...
Independent asked 20/9, 2016 at 0:26
16
I have a problem with my webpack project, so I was trying to import one class to another and instantiate it but suddenly an error appear in my console and my program stopped working, it was this:
U...
Presume asked 27/11, 2020 at 13:32
2
Solved
Is there any performance advantage or disadvantage of using ES modules over CommonJS modules in a nodejs backend project? I'm asking this because I see a lot of people using CJS still even though n...
Orthopedist asked 7/4, 2022 at 10:39
3
Solved
I am following a tutorial and it says
ES modules uses live bindings. It means a feature to support cyclical
dependencies.
But I don't clearly understand this concept. What does this mean?
Viafore asked 6/9, 2018 at 19:54
4
Solved
Calling setTimeout with setImmediate has unpredicted behaviour if using CommonJS modules. But if you switch to ESM ("type": "module" in package.json), it will always execute set...
Maharajah asked 30/12, 2023 at 18:18
2
My package.json file looks something like this:
{
...
"main": "index.js",
"type": "module",
"scripts": {
"devStart": "pm2 start ...
Wicketkeeper asked 25/11, 2021 at 17:46
26
Solved
I use the flag --experimental-modules when running my Node application in order to use ES6 modules.
However when I use this flag the metavariable __dirname is not available. Is there an alternative...
Epley asked 14/10, 2017 at 13:17
20
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').trigger...
Masturbate asked 18/4, 2020 at 15:27
4
Solved
I updated to nanoid4 and began getting the following error:
[ERR_REQUIRE_ESM]: require() of ES Module
[...]/node_modules/nanoid/index.js not supported. Instead change the
require of index.js in [....
Visualize asked 13/6, 2022 at 3:51
15
ES6 modules allows us to create a single point of entry like so:
// main.js
import foo from 'foo';
foo()
<script src="scripts/main.js" type="module"></script>
foo.js ...
Biodegradable asked 6/12, 2017 at 13:30
5
All modern versions of Node need to run packages as modules is "type": "module" in package.json, but I don't see any flags for npm init or yarn init that will add that property....
Rodrigorodrigue asked 16/7, 2020 at 8:6
6
Solved
We're trying to use the new ways of exporting and importing modules for ES6 with Node.js. It's important for us to get the version number from the package.json file. The following code should do th...
Jink asked 13/2, 2020 at 10:41
6
Solved
I'm new to Gulp and trying to automate some tasks. Here's my environment setup: npm version: 8.1.0, node version 17.0.1, gulp CLI version 2.3.0 and gulp version 4.0.2
And here's my gulpfile.js:
// ...
Novah asked 6/11, 2021 at 9:21
3
Solved
I'm rewriting some JS code on TypeScript and encounter with problems with module import. For example, I want to write my toggleVisiblity function. Here is code:
/// <reference path="../../typin...
Gwalior asked 3/12, 2016 at 13:29
2
I'm trying to get webpack to ignore an import, so that its imported by the browser using a native ES6 import statement, not webpack. I'm trying to get ffmpeg.js to import directly as it crashes web...
Ladonnalady asked 5/4, 2020 at 22:19
3
I'm loading a javascript file using jquery with the usual:
// file application.js
$.getScript("module.js", function(data, textStatus, jqxhr) { ... });
So far so good. Except that module.js uses ...
Disconnected asked 5/11, 2019 at 16:42
5
I'm trying to write a simple jest test for a 3rd party package were using that only exports an ES module. It's a wrapper around an http server.
Here is a test repo I setup (just run yarn &&...
Zymosis asked 25/7, 2021 at 16:40
1
Original question:JavaScript - Does the use of namespace imports have an effect on a module's treeshake-ability?
Assume that we are using ES6 module system. According to the docs, when we use an * ...
Lathy asked 10/3, 2023 at 18:14
© 2022 - 2024 — McMap. All rights reserved.