Questions tagged [esmodules]

57 questions
0
votes
0 answers

When bundling your app for the browser, how to support legacy cjs and modern es modules at the same time?

When bundling an ES module with webpack: https://webpack.js.org/guides/ecma-script-modules/ Does the tag gets automatically added to the index.html file? Is there a plugin for it? Also, how can I make…
cbdeveloper
  • 27,898
  • 37
  • 155
  • 336
0
votes
1 answer

Destructured imports vs namespace in react libraries using typescript

My question is : is there any consequences in performance if using for example: import * as Reanimated from 'react-native-reanimated' Instead of : import { useSharedValue, useAnimatedStyle, withspring, interpolate, Extrapolate } from…
0
votes
0 answers

How to run amcharts on Electron

I am working with Electron 11.0.2, and I wanted to integrate the amcharts library into a program I was working on. I created a test script loaded via the script tag on the html loaded into the Electron renderer process. The amcharts library was…
Eazicoding
  • 191
  • 9
0
votes
0 answers

Use import statement in Babel plugin

I'm currently writing a babel plugin. I have a folder called plugin a package.json and the following file: // index.js import template from "@babel/template"; module.exports = function(babel) { // some code } Then I have a folder called…
Jomy
  • 514
  • 6
  • 22
0
votes
1 answer

How can I dynamically load a JSON file inside an ECMAScript module?

I am doing: let filePath = '../../data/my-file.json' import inputArray from filePath assert { type: 'json' } This is the result I get: file:///.../script.mjs:5 import inputArray from filePath assert { type: 'json' } …
Tiago Bértolo
  • 3,874
  • 3
  • 35
  • 53
0
votes
1 answer

How to determine the module system from a node js library code for importing config file

I'm working on adding support for .js config file in a NodeJS library. NodeJS support two module system - ESM & CommonJS - and since javascript files with .js can be treated as an ES Module or a Common JS module based on the what is defined as type…
Anshul Sahni
  • 626
  • 8
  • 21
0
votes
1 answer

How can I import NeDB as ES Mobule

I need to import NeDB and I need to do this using ES Module, what I need from NeDB is DataStore. When I try to import DataStore using the usual synthax : import { DataStore } from 'nedb'; I have this error : Named export 'Datastore' not found. The…
nem0z
  • 1,060
  • 1
  • 4
  • 17
0
votes
2 answers

Can I use ES modules in IBM Cloud Functions (node.js) or is only Common JS supported?

When I create a Node.js v16 function action from a zip file containing a simple estest.js: function main(params) { return { message: 'Hello World' }; } and package.json containing "type": "module" I get: { "error": "Initialization has failed…
0
votes
1 answer

Nodejs Question about circular dependency

I was testing circular dependency with commonjs. //index.js console.log('main starting'); const a = require('./a.js'); const b = require('./b.js'); console.log('in main, a.done = %j, b.done = %j', a.done, b.done); //a.js console.log('a…
MINJA KIM
  • 876
  • 1
  • 8
  • 22
0
votes
1 answer

Circular import error with sequelize and Esmodules

i'm working on a project with tinyHttp V2 which uses only EsModules. I'm trying to make a sample project with some sequelize models but i'm not able to start anything, typescript compilation is complaining about circular import inside models (which…
0
votes
0 answers

Exporting a destructured object possible?

I'm writing an ESmodule and have the following code: const object = { key1: 'test', key2: 'test2', } export { ...object } It seems you can't export a destructured object? Is there a workaround that would look clean?
Justin
  • 623
  • 1
  • 10
  • 24
-2
votes
1 answer

Why import can be used in this commonjs module?

Code is here: https://github.com/timewalker08/wechaty-test/tree/master According to nodejs document: If the nearest parent package.json lacks a "type" field, or contains "type": "commonjs", .js files are treated as CommonJS. If the volume root is…
timewalker
  • 29
  • 7
1 2 3
4