Questions tagged [mjs]

40 questions
370
votes
3 answers

What is the difference between .js and .mjs files?

I have started working on an existing project based on Node.js. I was just trying to understand the flow of execution, where I encountered with some *.mjs files. I have searched the web where I found that these are module based JS-files. I want to…
Keval Bhogayata
  • 4,422
  • 3
  • 13
  • 36
12
votes
2 answers

exports is not defined in ES module scope

I created nest js project as following. nest new project-name and imported following from nuxt3 which is of type module of node js with mjs file extension (type definition of import doesn't require to write mjs). import { ViteBuildContext,…
Anonymous Creator
  • 2,968
  • 7
  • 31
  • 77
8
votes
1 answer

How to run ECMAScript (mjs files) with nodemon?

I am able to run mjs files with nodejs using --experimental-modules flag. node --experimental-modules index.mjs package.json: { "name": "mjs-tests", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { …
boleeluchshiy
  • 121
  • 1
  • 1
  • 9
5
votes
3 answers

Nuxt3 - `_nuxt`-directory not found (404) on GitHub Pages

(I know it might sound similar to missing js files from _nuxt folder, but unfortunately, I was not able to understand the answer from there) When I deploy my dist-folder to GitHub Pages, it contains dist | _nuxt | css/main.css |…
STh
  • 746
  • 9
  • 24
5
votes
3 answers

Importing using relative paths in Node.js with ES Modules

In the past, I used app-module-path whenever I wanted to have relative paths in my Node.js apps. If I use ES Modules through the .mjs format, how do I have the same functionality where a certain directory path becomes relative? In an alternative…
Kevin Ghadyani
  • 6,829
  • 6
  • 44
  • 62
4
votes
1 answer

Is there a way to create a module that can be consumed by both ESM and CJS applications?

I have a backend CJS application & a frontend ESM application. And a node module I have created in ESM. The node module works fine for my ESM application because they are both using ESM import syntax. Trying to consume it in the CJS application…
warahi
  • 41
  • 4
4
votes
1 answer

isomorphic code for native node.js and browser crypto

There is the isomorphic-webcrypto that pretends doing that but doesn't : it builds separate build for each target. There is the noble-crypto way to do it, but it's based on if-else conditions and fails if I want an isomorphic mjs code. Finally,…
1000i100
  • 400
  • 1
  • 3
  • 13
3
votes
0 answers

use require() in .mjs bundles - Angular 13

I recently upgraded my project to Angular 13, I noticed that the new ng-packgr 13 bundles in .mjs extension by default. I have lots of code that uses require() to import some static assets and files. I can change them to import() but is there any…
vp310
  • 300
  • 1
  • 9
2
votes
1 answer

Is there a way to enable VSCode intellisense for a node .mjs project?

I'm writing a small node cli app in a sub-folder of my project. I'm using .mjs files. Is there a way to enable VSCode intellisense? I tried with a .jsconfig with no luck.
Fred Hors
  • 3,258
  • 3
  • 25
  • 71
2
votes
1 answer

There is input image field without any input image

I am building a WebApp and I am trying to add my own model instance in the place of default image field BUT I didn't find any ImageField. The Problem Page is showing ImageField but i didn't find any image field in template. models.py class…
Lars
  • 1,234
  • 1
  • 8
  • 31
2
votes
0 answers

Protractor - Must use import to load ES Module

Using protractor and trying to switch to using es6 import instead of commonjs require approach I changed package.json and added (in the top section) "type": "module" I renamed my two app files from .js to .mjs I changed my protractor conf.js to be…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
2
votes
1 answer

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't provided a require function, instead requiring the use of the new import syntax. My…
Danii
  • 167
  • 3
  • 9
2
votes
1 answer

AVA unit tests fails passed Javascript test specs

I am currently working with ES6 modules with .mjs extensions and creating test cases for some functions. I have chosen AVA due to its support of this extension type but the test executions are not running as expected. I assume the script is not…
O.O
  • 1,389
  • 14
  • 29
2
votes
1 answer

Can not load local dir Node.js modules when using --input-type

Node.js 12+ has new command-line option --input-type to run script inside Bash heredoc. However, it doesn't seem to be able to find Node.js modules installed in ./node_modules Here's how I install a module: cd test npm i moment And run Node.js with…
Dee
  • 7,455
  • 6
  • 36
  • 70
2
votes
2 answers

load ecmascript module (.mjs file) as main entry of nodejs cli

is there a way to use an ecmascript module file as the main entry file to a cli exported using the package.json bin entry? i guess i would need to somehow provide the --experimental-modules flag, but i can not figure out a way to do this without…
1
2 3