The standard module system for JavaScript, introduced in ECMAScript 6 (2015).
Questions tagged [es6-modules]
2668 questions
1
vote
2 answers
React.js / CRA, How to call or import a javaScript function from another file?
My code is getting longer so I decided to transfer them to other javaScript file.
I followed this relevant topic regarding my question but Why I getting an error i just copy and paste everything?
In above link here's the…

devjson
- 113
- 2
- 16
1
vote
1 answer
ES6 "Import()" issues "MODULE_NOT_FOUND" [Webpack - NodeJS]
I transpile my ES6 code using Webpack along with BabelJS in NodeJS environment. The problem is that, when I try to import a set of specific .js modules, the MODULE_NOT_FOUND exception would be thrown. This is the main chunk of code I've written so…

noteworthy
- 11
- 3
1
vote
2 answers
Browser accepts "classic" js script-tag, but not ES6 modules — MIME error w/ Node http server
I want to play with ES6 modules, so I decided on using Node as a simple web server to avoid all CORS related errors I first encountered when doing it locally. Now I get MIME type related errors in the browser which I can't quite grasp.
Here is my…

Audun Olsen
- 597
- 6
- 17
1
vote
1 answer
What type should I use to document ES6 module parameters in jsdoc?
Let's say I import an ES6 module like this:
import * as moduleVar1 from "./variant/One.js";
import * as moduleVar2 from "./variant/Two.js";
import * as moduleVar3 from "./variant/Three.js";
Now, I e.g. select one of the loaded modules…

rugk
- 4,755
- 2
- 28
- 55
1
vote
1 answer
Importing / Changing HTML content (after ES6 update)
I have been trying to dynamically change the content of my HTML page by importing external HTML-files. I found a way to do this using HTML imports but if I have understood it correctly this feature is going to become obsolete in because of the ES6…

August Tengland
- 91
- 6
1
vote
0 answers
Is it possible to import an object within another?
I have a few files that export an object to be reused as models. Within some objects I use a model from another file. This works fine as long as the other model doesn't use the other file, but if they do then one becomes undefined. I figure this is…

James
- 1,045
- 8
- 17
1
vote
0 answers
Rollup ES6 access module in multiple bundles
How can I reuse code from another bundle so I don't end up bundling that code again? For example:
One.js
import $ from './jQuery';
import Something from './Something';
Something.do($('.test'));
After Rollup: bundleOne.js
(function () {
var $ =…

JSdev
- 21
- 1
1
vote
1 answer
What is the most forwards-compatible way of importing CommonJS from TypeScript?
Of these three ways of importing a CommonJS module from TypeScript:
import * as foo from "foo
import foo = require("foo")
const foo = require("foo")
Which is most forwards-compatible with both TS and the ES module spec?
That is, when/if the "foo"…

Max Heiber
- 14,346
- 12
- 59
- 97
1
vote
1 answer
How can I import a CommonJS module that exports a single function from TypeScript
Given this CommonJS module:
// cjs.js
module.exports = () => console.log("hi");
What can I put in my .d.ts
// cjs.d.ts
export ????
So that I can do a star import like this from a TypeScript file and pick up the correct types:
// main.ts
import *…

Max Heiber
- 14,346
- 12
- 59
- 97
1
vote
1 answer
namespace export from index.js
My index.js in a given directory exports several things like this:
export * from 'fileOne';
export * from 'fileTwo';
export * from 'fileThree';
I want to name space the stuff from file4, something like this:
export { default as mockStuff } from…

Adam Jenkins
- 51,445
- 11
- 72
- 100
1
vote
1 answer
How Would one fix "Uncaught ReferenceError: canv is not defined at otherfile.js:3" when canv is being imported from main.js
I am exporting a canvas element object from my main.js file to a separate file that I would like to handle the events of the canvas object. I have imported it before when it would be referenced in a function of the other file, however whenever I try…

robert gibson
- 111
- 1
- 4
1
vote
0 answers
Meteor Babel ES6 error: “This API has been removed…”
I have a meteor method call that has this below ES6 code which fails to transpile due to the error noted below.
theOthers.forEach(member => {
if (member.notifications) {
const contextIdIndex = member.notifications.findIndex(
…

Emo
- 580
- 1
- 8
- 27
1
vote
1 answer
How to resolve the ESLint error "Prefer default export ..."?
I have the following module, in which there is a named function...
eslint ( airbnb ) is raising an error:
8:1 error Prefer default export import/prefer-default-export
How should I restructure my code to comply to this requirement?
exports /…
user762579
1
vote
1 answer
view es6 module export/import dependencies
I have a web project with over 60 es6 modules that use export and import. I am looking for a way to graph, or map out, the relationships between the modules. I am looking for circular dependencies and opportunities for code splitting and just…

Richard Greenwood
- 876
- 1
- 10
- 20