Category "es6-modules"

(node:9374) Warning: To load an ES module, set "type": "module"

I just started to learn React today. How do I get rid of that error message on my Console in the Terminal in Visual Studio. (node: 9374)Warning: To load an ES m

NodeJS with ESM: internal/process/promises:246 | triggerUncaughtException(err, true /* fromPromise */) | finalizer.unsubscribe is not a function

I am creating an observable (RxJS) in NodeJS using ESM. Inside the observable I am performing a query with mongoose. I get the result, but the console returns e

Best practice for importing component from components library in React.js

When I create components in React, they're all in a folder called component and each component has a dedicated folder with the same name as the component itself

How To Check If Node EsModule Was Imported Or Ran Directly

Node.js 13 recently rolled out an experimental ESModule loader, starting to take the switch away from CommonJS. However, code ran in an ESModule in Node.js isn'

detect whether ES Module is run from command line in Node

When using CommonJS modules in Node, you can detect whether a script is being run from the command line using require.main === module. What is an equivalent wa

Is there a way to "npm init" an ES module?

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 a

'X Is not a function' in CommonJS

I've got the following code I transformed from a Trypescript, ESM-syntax based file to a Javascript, CJS-syntax file. const apiClientFactory = require("@vue-sto

How do I import ES6 Module within a create-react-app without causing tests to fail?

When I follow the instructions found here and add the import reference as they specify: import "@ui5/webcomponents/dist/Button"; the application works fine a

How to load a javascript module with jquery

I'm loading a javascript file using jquery with the usual: // file application.js $.getScript("module.js", function(data, textStatus, jqxhr) { ... }); So far

Why and when to use default export over named exports in es6 Modules?

I have referred all the questions in stackoverflow. But none of the suggested why and when to use default export. I just saw that default can be metioned "Wh

How to set up Jest w/ESM to recognize non-cjs modules in node_modules

Have got a successful jest/esm setup, however occasionally a module is released that specifies both a main key (for commonjs) and a module key (for ESM) in its

Can I use ES Modules library from CDN?

I want to use this library via CDN.https://www.jsdelivr.com/package/npm/lit-element My js code is here. import { LitElement, html } from "https://cdn.jsdelivr

ES6 Modules : Importing a module in an Angular component

I have an ES6 module where I am exporting a library. I want to be able to use this module in an Angular component. I cannot have the library files locally withi

ES6 Modules : Importing a module in an Angular component

I have an ES6 module where I am exporting a library. I want to be able to use this module in an Angular component. I cannot have the library files locally withi

Access html5 data-* attributes defined in a module script

When loading scripts without using modules, I could use the document.currentscript to access custom attributes. E.g. <script src="js/myscript.js" data-custom

ES2015 import doesn't work (even at top-level) in Firefox

These are my sample files: <!DOCTYPE html> <html> <head> <title>Test</title> <script src="t1.js"></script> </h

How do I detect if an ES Module is the main module?

How can I detect if an ECMAScript module is the main module? This is easy for CommonJS modules (see Detect if called through require or directly by command line

ES6 modules - imported constants undefined if not in React component

The only similar question I have found is this one but I can't see how would I have caused a circular dependancy in this case: I have a file exporting constants

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:

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 ... priva