47 questions
1
vote
0
answers
4k
views
Can't import the named export 'XXX' from non EcmaScript module (only default export is available)
Working on a calendar display for a React project, and after creating this component, I have this error now appearing.
The error, "Failed to compile.
./node_modules/date-fns/intervalToDuration....
-1
votes
1
answer
4k
views
Is there a way to convert mjs files to js? [closed]
Is there a way to convert .mjs files to .js? Not all hosts support mjs files yet, so I'd like to convert mjs files to js files.
Background: Mozilla's PDFjs updated their code to use JavaScript modules ...
0
votes
2
answers
114
views
Why is my Node.js code not reaching the unreachable part after processing events with for-await-of loop on EventEmitter?
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo'...
1
vote
0
answers
100
views
New lines from my mdx file are not rendering on my website, how can I fix this?
I'm using markdown files in my Next JS project, but when I view my files on local host there is no spaced between any lines or paragraphs. How can I fix this?
Markdown file:
**Research**
The ...
0
votes
1
answer
42
views
Netbeans 21 and .mjs- filetype
I just installed Netbeans V21 and saw that .mjs- files are not recognized by the spellchecker, even after importing the setup from V20.
Then I opened Tools/ Options/ Miscellaneous/ Files and set "...
1
vote
1
answer
8k
views
Unrecognized key(s) in object: 'appDir' at "experimental" - Next.js 14.0.4 error
I updated the next.js and appeared an error. I searched that error and I didn't found the solution, even the official website of the next.js.
The error is here:
> [email protected] dev
> next dev
▲ ...
1
vote
1
answer
856
views
Webpack cannot resolve /index.(js|jsx) files when package is type module
I'm pretty new to Webpack configuration and difference between cjs, mjs etc.
When trying to build a component lib bundled by Webpack, im coming across this error when building (webpack command)
...
6
votes
4
answers
5k
views
Angular 17 SSR - how to compile server files (*.mjs) to *.js
my hosting provider requires server files to be compiled to CommonJs and Angular 17 by default compiles files to Module JS *.mjs, I've tried to change the tsconfig.json but it changes the scope for ...
3
votes
0
answers
283
views
Problem parsing a mjs file with babel in a CRA
I have a project made with CRA where I've imported an external library with this package.json
"type": "module",
"main": "build/index.umd.js",
"module":...
0
votes
0
answers
137
views
Running javascript files without using modules
I'm working on a project in HTML and have been running JavaScript modules from it. However, I'm encountering the error in my browser that CORS is blocking a local file.
I did some research and I heard ...
0
votes
1
answer
825
views
"module has no exports" error - works fine on stackblitz but fails locally
I'm trying to get up and running with shikiji (a rewrite of shiki). As such, I've created this minimal example Next.js 13 project. It's the boilerplate project you get with npx create-next-app@latest ...
1
vote
0
answers
261
views
Error importing mjs file into Typescript: TS2307: Cannot find module '../../env.mjs' or its corresponding type declarations
Using this library: https://env.t3.gg/docs/nextjs to build env validator in nextjs. I am getting following error on "yarn dev": TS2307: Cannot find module '../../env.mjs' or its ...
3
votes
3
answers
5k
views
MIME type of .mjs files is "text/html" when deploying React (ViteJS) app to Azure Kubernetes
I've built a React application utilizing ViteJS with TypeScript. I've built the project using tsc && vite build. I've then built the Docker image based on my Dockerfile:
FROM node:18.12.0
COPY ...
0
votes
0
answers
13
views
Node.js global variable error 'Uncaught TypeError: "object" is read-only' [duplicate]
I am trying to check if 'object' is saved in Local storage, and if it is then assign a global variable the object in a separate file, however, in the console it is saying Uncaught TypeError: "...
0
votes
1
answer
270
views
Telegram bot: SyntaxError SyntaxError: Unexpected end of JSON input when I want to upload a video
I'm trying to do a telegram bot who send vidéo
import fetch from 'node-fetch'
fetch("https://api.telegram.org/bot<api>/sendVideo", {
method: "POST",
headers: {
...
0
votes
1
answer
1k
views
Error [ERR_REQUIRE_ESM]: require() of ES Module when running `prisma db seed `
I have a project that is using TypeScript, Prisma & NextJS.
I want to see my database with prisma using the yarn prisma db seed command.
However, I am facing issues.
The problem is the file that I ...
0
votes
1
answer
23
views
Not sharing single instance of jQuery/simple assignment failing?
I don't know how to explain this one. I'm trying to debug import 'datatables.net' isn't setting $.fn.dataTable. My theory was that I have 2 copies of jquery.
To debug I added
$.poop = 345
$.fn....
0
votes
0
answers
76
views
async function wont break node.js (.mjs)
I'm trying to pause this function using the breakTheLoop var but it wont work.
This is the code if anyone could help me out
`
async afk(message) {
var breakTheLoop = false;
while (!...
0
votes
1
answer
648
views
Unable to build lambda with webpack and fontkit
I am trying to add PDF generation to my mailer script implemented as AWS Lambda function. It is working fine locally, etc. When I am packing it with webpack 4, it does not work.
My webpack config is ...
1
vote
0
answers
325
views
Unable to load .mjs file and run tests with Mocha
I am unable to load an .mjs file and run tests with mocha.
I have tried mocha v.7.2.0 with flag --experimental-modules and v.10.0.0 without flag.
I am using node v.14.15.4.
The import statement that I ...
0
votes
1
answer
771
views
Import a function in a .mjs script
Need some help with using a .mjs script and .js as well.
I have one script.mjs file that looks like this. Simplifying here (the script needs to be .mjs file)
import test from './test.js';
test();
...
3
votes
0
answers
807
views
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. ...
7
votes
3
answers
3k
views
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
...
1
vote
0
answers
205
views
Is there any way of changing the relative path of a mjs file (to make it see a different node_modules folder)?
When I'm executing pure node.js scripts I can change the path where it searches for node_modules as the following:
export NODE_PATH="/home/user/node_modules"
node "/home/user/different/...
0
votes
1
answer
2k
views
Angular Apollo V3 - Jest error: Cannot find module 'apollo-angular'
I recently updated angular apollo from 2.6.0 to the v3.0.0 and this update broke my tests.
I am using jest for my unit tests, while the app compiles and runs fine, my tests are unable to import any ...
25
votes
2
answers
70k
views
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 ...
1
vote
0
answers
1k
views
Load a CJS module config inside another file
I'm trying to load a config inside a node module but I'm not sure which is a good practice to do it, I have this scenario:
A config my.config.js:
module.exports = {
content: [
'./src/**/*.{tsx,...
1
vote
1
answer
1k
views
"@angular/cdk": "^12.2.0", mismatch with angular material "@angular/material": "^13.1.1",
Don't say "downgrade version" to this question. I cant do it because management want to maintain the latest versions. Is there any other alternatives...like converting mjs to js file in ...
0
votes
1
answer
2k
views
[react]Getting error code HTTP/1.1 500 Internal Server Error when testing app.post to create a database entry
I am trying to build a website that displays information from a database. My controller file has the code
import express from 'express';
import * as exercises from '../REST API/exercises_model.mjs';
...
2
votes
1
answer
296
views
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.
1
vote
0
answers
1k
views
Webpack 3 and .cjs/.mjs files
Context
Our product is (sadly) still on Webpack 3. Hope to upgrade, but in the meantime, I am trying to use an npm library that bundles cjs, mjs and iffe files. (See package.json excerpt below).
The ...
5
votes
2
answers
2k
views
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 ...
1
vote
1
answer
3k
views
Which should have .mjs extension, the importing file or the exporting file, or both?
I have a silly doubt. Which file, the importing file, the exporting file or both should have the .mjs file extension?
Specifically for NodeJS.
I have searched the web but didn't get my exact answer.
...
4
votes
2
answers
1k
views
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 ...
2
votes
1
answer
142
views
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 ...
1
vote
1
answer
3k
views
Jest test functions that define variables in it
I want to write some Jest tests for JavaScript functions in a .mjs file. Within these functions, variables are defined by calling other functions. For example:
export function getCurrentVideo() {
...
0
votes
1
answer
351
views
Is there a way to show Intellisense autocomplete of classes that are imported to .js
I have 2 files, module.mjs and project.js. In module.mjs there are all functions and classes used in project.js file.
My problem is that I can't see class methods or suggestions or even class ...
2
votes
0
answers
717
views
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 ....
2
votes
1
answer
2k
views
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 ...
607
votes
4
answers
478k
views
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 ...
10
votes
1
answer
16k
views
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": "",...
2
votes
1
answer
1k
views
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 ...
2
votes
1
answer
1k
views
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 ...
2
votes
2
answers
3k
views
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 ...
1
vote
1
answer
347
views
NodeJS require module namespaces
I thought about having my, on npmjs released, module split into 2 or more parts (versioned), but both easily requirable / importable.
The result should be:
//index1.js
const themodule = require('...
2
votes
2
answers
2k
views
Fail to create variable using eval in Node.js ES6
It seems not possible to create a variable using eval in Node.js ES6 but I can't understand why. This happens to me on CentOS 7, but I don't believe OS is the problem here.
Regular Node.js file (test....
5
votes
2
answers
19k
views
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 ...