Error [ERR_REQUIRE_ESM] in nuxtjs 2 while deploying with ec2 - node.js

Getting error of Error [ERR_REQUIRE_ESM] while deploying nuxtjs 2 application.
Scripts:
"build": "nuxt build",
"start": "./node_modules/pm2/bin/pm2 start pm2.config.json"
Errors:
Error [ERR_REQUIRE_ESM]: require() of ES Module /var/app/current/node_modules/string-width/index.js from /var/app/current/node_modules/wrap-ansi/index.js not supported.
Instead change the require of /var/app/current/node_modules/string-width/index.js in /var/app/current/node_modules/wrap-ansi/index.js to a dynamic import() which is available in all CommonJS modules.
at Module.Hook._require.Module.require (/var/app/current/node_modules/require-in-the-middle/index.js:80:39)
at Object. (/var/app/current/node_modules/#nuxt/cli/dist/cli-index.js:15:18)
at Object. (/var/app/current/node_modules/nuxt/bin/nuxt.js:6:1)
at /var/app/current/node_modules/pm2/lib/ProcessContainer.js:303:25
at wrapper (/var/app/current/node_modules/async/internal/once.js:12:16)
at WriteStream. (/var/app/current/node_modules/pm2/lib/Utility.js:186:13)
at WriteStream.emit (node:events:527:28)
at FSReqCallback.oncomplete (node:fs:188:23)
EDIT:
AWS EC2 : upgrade from AMI 1 to AMI 2
Node: 16.15.1
Npm: 8.11.0

Related

Problems with running Nuxt 3 [3.0.0-rc.3] on Apple silicon

I followed the quick guide to create an app using the operating system macOS Monterey 12.4 MacBook Pro M1 Max / Node v16.15.0 and also tried with 18.
When visiting the host http://localhost:3000, it repeats the error constantly [below shows the error in the terminal]. It looks like it could be a problem with the hot reload.
I tried reinstalling the node using brew and nvm for different node versions. This problem only curves on apple silicon, not on Intel-based machines. How can I solve this problem?
Creating nuxt app :
npx nuxi init nuxt-app
package.json :
{
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview"
},
"devDependencies": {
"nuxt": "3.0.0-rc.3"
}
}
After running npm run dev it through an error :
Nuxt CLI v3.0.0-rc.3 11:19:41
11:19:41
> Local: http://localhost:3000/
> Network: http://172.30.1.18:3000/
✘ [ERROR] Cannot read directory "../../..": operation not permitted
ERROR 11:19:43 AM [vite] error while updating dependencies: 11:19:43
Error: Build failed with 1 error:
error: Cannot read directory "../../..": operation not permitted
at failureErrorWithLog (/Users/USERNAME/nuxt-appnode_modules/esbuild/lib/main.js:1603:15)
at /Users/USERNAME/nuxt-appnode_modules/esbuild/lib/main.js:1249:28
at runOnEndCallbacks (/Users/USERNAME/nuxt-appnode_modules/esbuild/lib/main.js:1034:63)
at buildResponseToResult (/Users/USERNAME/nuxt-appnode_modules/esbuild/lib/main.js:1247:7)
at /Users/USERNAME/nuxt-appnode_modules/esbuild/lib/main.js:1356:14
at /Users/USERNAME/nuxt-appnode_modules/esbuild/lib/main.js:666:9
at handleIncomingPacket (/Users/USERNAME/nuxt-appnode_modules/esbuild/lib/main.js:763:9)
at Socket.readFromStdout (/Users/USERNAME/nuxt-appnode_modules/esbuild/lib/main.js:632:7)
at Socket.emit (node:events:527:28)
at Socket.emit (node:domain:475:12)
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/vue.js?v=3f037d64 optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/vue.js?v=3f037d64 optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/vue.js?v=3f037d64 optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/vue.js?v=3f037d64 optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/vue.js?v=3f037d64 optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/vue.js?v=3f037d64 optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/vue.js?v=3f037d64 optimized info should be defined (repeated 20 times)
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/ufo.js?v=2227049b optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/ufo.js?v=2227049b optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/ufo.js?v=2227049b optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/ufo.js?v=2227049b optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/ufo.js?v=2227049b optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/ufo.js?v=2227049b optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/vue.js?v=3f037d64 optimized info should be defined 11:19:43
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/vue.js?v=3f037d64 optimized info should be defined 11:19:43
ℹ Vite server warmed up in 112ms 11:19:43
ℹ Vite client warmed up in 438ms 11:19:43
✔ Vite server built in 335ms 11:19:43
✔ Nitro built in 174 ms nitro 11:19:43
I have updated npm to 8.11.0, and no issue on M1 Max.
Vesrions I used:
Nuxt: 3.0.0-rc.3
Node: v16.15.0
Npm 8.11.0

node error when calling "yarn start" in an app created by create-react-app

I recently created a new project with create-react-app, installed all newest packages for an old create-react-app project (which was using react-scripts 3.4.1, and the new project is using 5.0.0) and copied the old code and asset files over. To my puzzlement, the new project throws an error whenever I call "yarn start"
Starting the development server...
node:events:498
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (node:_http_client:442:9)
at TLSSocket.emit (node:events:520:28)
at TLSSocket.emit (node:domain:475:12)
at emitErrorNT (node:internal/streams/destroy:164:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -54,
code: 'ECONNRESET',
syscall: 'read'
}
Node.js v17.4.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
For what it's worth, the old project doesn't throw an error despite that the src code is the same. The only difference is the packages.
I googled around and followed various advice, including this one: https://medium.com/#premal.katigar/how-to-fix-throw-er-unhandled-error-event-30172323a973. All to no avail.
There are a couple of clues that could be useful:
I use an antd landing page, which is basically a bunch of .jsx and .less files that constructs a page. If I replace that landing page code with some simple jsx component, e.g. something that simply returns an h1 tag, then there is no longer this node error. Yarn start would start the project fine.
The only differences between the old project that starts fine even with the aforementioned antd landing page, and the new one that throws the above error are that 1) the new project contains all the newest versions of the required packages, since I used "yarn install" for all the required packages 2) since I'm using the newest version of antd, instead of using "customize-cra", "react-app-wired", "babel-plugin-import" and "less-loader", I was simply using "craco-less". So the old project's "yarn start" actually called "react-app-rewired start" and the new one actually called "craco start".
I also tried downgrading node version from 17 to 16, and the error remained.
Any clue what might be the issue?

Electron and couchbase: the module was compiled against a different node.js version (win)

Question:
I am trying to use couchbase in an electron application, but fail to run the electron application as soon as I include the couchbase module. How can I use couchbase with electron?
Error message:
C:\dev\app>npm start
> eej#1.0.0 start C:\dev\app
> electron .
App threw an error during load
Error: The module '\\?\C:\dev\app\node_modules\couchbase\build\Release\couchbase_impl.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 76. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at process.func (electron/js2c/asar.js:140:31)
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1016:18)
at Object.func (electron/js2c/asar.js:140:31)
at Object.func [as .node] (electron/js2c/asar.js:140:31)
at Module.load (internal/modules/cjs/loader.js:816:32)
at Module._load (internal/modules/cjs/loader.js:728:14)
at Module._load (electron/js2c/asar.js:717:26)
at Function.Module._load (electron/js2c/asar.js:717:26)
at Module.require (internal/modules/cjs/loader.js:853:19)
My main.js file begins like this:
const { app, BrowserWindow } = require('electron')
var couchbase = require('couchbase');
function createWindow () {
What I have tried already:
removing the node_modules directory and lock file and reinstalling via npm i
installing and running electron-rebuild
using the --update-binary switch when running npm i
downgraded the npm version to an LTS version
Background information:
Node version:
PS C:\dev\app> node --version
v12.16.1
PS C:\dev\app> electron --version
v8.0.1
Electron uses node 12.13.0:
We are using node 12.13.0, Chrome 80.0.3987.86, and Electron 8.0.1.
The version of electron-node and standalone node differ. I am not sure if this is okay?!
Content of my package.json file:
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"couchbase": "^3.0.0",
"electron": "^8.0.1",
"electron-rebuild": "^1.10.0"
},
"dependencies": {
"node-gyp": "^6.1.0"
}
}
Similar questions:
Couchbase Node compiled against different node version: After I have added a comment I discovered that it is a unix specific question.
Node - was compiled against a different Node.js version using NODE_MODULE_VERSION 51: I went through nearly all of the suggestions, but none of them seemed to work for me.

WebPack module build error

Having trouble with building react project with WebPack.
Getting the following error output, is there a way to get a more info out of web pack on this issue.
running: webpack --display-error-details --display-reasons --progress -p --config webpack.config.prod.js
62% 478/543 build modulesError
at NormalModule.<anonymous> (...../node_modules/webpack/lib/NormalModule.js:113:20)
at NormalModule.onModuleBuild (..../node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (..../node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at ...node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (....node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
at .../node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:438:3)
69% 1917/1919 build modules

webpack --progress Error: write EINVAL

I'm on Windows 10 recently upgraded my node.js to version 7.1.0. I started to get the following error every time I ran the webpack command with --progress flag.
$ webpack --progress
Node Environment: development events.js:160
throw er; // Unhandled 'error' event
^
Error: write EINVAL
at exports._errnoException (util.js:1022:11)
at WriteStream.Socket._writeGeneric (net.js:715:26)
at WriteStream.Socket._write (net.js:734:8)
at doWrite (_stream_writable.js:334:12)
at writeOrBuffer (_stream_writable.js:320:5)
at WriteStream.Writable.write (_stream_writable.js:247:11)
at WriteStream.Socket.write (net.js:661:40)
at E:\Projects\wad\node_modules\webpack\bin\convert-argv.js:421:20
at Compiler.<anonymous> (E:\Projects\wad\node_modules\webpack\lib\ProgressPlugin.js:77:4)
at Compiler.applyPlugins (E:\Projects\wad\node_modules\tapable\lib\Tapable.js:26:37)
at Compiler.<anonymous> (E:\Projects\wad\node_modules\webpack\lib\Compiler.js:193:12)
at Compiler.emitRecords (E:\Projects\wad\node_modules\webpack\lib\Compiler.js:282:37)
at Compiler.<anonymous> (E:\Projects\wad\node_modules\webpack\lib\Compiler.js:187:11)
at E:\Projects\wad\node_modules\webpack\lib\Compiler.js:275:11
at Compiler.applyPluginsAsync (E:\Projects\wad\node_modules\tapable\lib\Tapable.js:60:69)
at Compiler.afterEmit (E:\Projects\wad\node_modules\webpack\lib\Compiler.js:272:8)
at Compiler.<anonymous> (E:\Projects\wad\node_modules\webpack\lib\Compiler.js:267:14)
at E:\Projects\wad\node_modules\async\lib\async.js:52:16
at done (E:\Projects\wad\node_modules\async\lib\async.js:246:17)
at E:\Projects\wad\node_modules\async\lib\async.js:44:16
at E:\Projects\wad\node_modules\graceful-fs\graceful-fs.js:43:10
at FSReqWrap.oncomplete (fs.js:111:15)
It works fine without the --progress flag and webpack --progress was working fine on node.js v6.x.x. Using webpack --progress with node v.7.1.0 on the same project but another windows 10 machine also works fine.
What does this error mean?
This is a problem of the version node, use the version 6.9 and success
I had the same problem, and i uninstall node7.1, reboot and install node6.9 and all ok
It seems there a bug at node js v7.1.0 nodejs/node#9542. Update to the latest version v7.3.0 and everything will be ok.

Resources