generating new nestjs module results in Error: Failed to execute command - node.js

I'm using MacOS monterey with M1 chip as my operating system. installed NestJS cli using this command: sudo npm install -g #nestjs/cli
when creating new nest project using nest new message everything works fine, but when I try to create new module using this command nest generate module messages I face error.
why does this happen? I tried installing schematics using npm i -g #nestjs/schematics, I don't know if I should've installed it but this didn't help anyway.
The error I face is:
/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:338
throw new Error(`Unknown argument ${key}. Did you mean ${(0, yargs_parser_1.decamelize)(key)}?`);
^
Error: Unknown argument skipImport. Did you mean skip-import?
at parseArgs (/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:338:19)
at main (/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:122:49)
at Object.<anonymous> (/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:367:5)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
Failed to execute command: node #nestjs/schematics:module --name=messages --no-dry-run --no-skipImport --language="ts" --sourceRoot="src" --spec.
worth noting that I don't face any issues when I do the same thing on ubuntu 20 or 22

Quick solution:
add this to your nest-cli.json
"root": "src"
change into the src of your project folder
cd src
run
nest generate module messages
if the above does not work also try changing the version of packages in package.json to
"#nestjs/cli": "8.2.6",
"#nestjs/schematics": "8.0.11",
removing the node modules in the current project
reinstalling the nest cli with
npm uninstall -g #nestjs/cli
npm i -g #nestjs/cli#8.2.6

this is a bug on the latest version of #nestjs/cli (v8.2.7). Downgrade it to 8.2.6 and it will work (I tested it). It was reported here: https://github.com/nestjs/nest-cli/issues/1693
Also, I don't recommend using the global version of the CLI. Instead, use npx nest or yarn nest.

Related

cannot use native node module in electron-forge app

I am trying to use pkcs11js in an electron app created with electron-forge using webpack template.
But I got the error
Error: C:\ws-p\electron-test\.webpack\main\349a63bd9833f80e7879a5bbfb2a4af2.node is not a valid Win32 application.
←[90m at Object.Module._extensions..node (internal/modules/cjs/loader.js:1122:18)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m
There are lots of questions asked around but none of the provided solutions/answers worked for me so far.
None of these worked out:
remove & reinstall node_modules
use electron-rebuild (although electron-forge uses this internally)
use node-gyp rebuild --target=13.1.0 --arch=x64 --dist-url=https://electronjs.org/headers manually for the package
Npm steps defined in electron docs
Environment:
Windows 10 Pro
Node 14.16.1
electron: 13.1.0
electron-rebuild: 2.3.5
electron-forge: 6.0.0-beta.57
pkcs11js: 1.2.4
You should use the Electron Forge Webpack template which has better support for native modules.
There is currently an open issue for this functionality caused by the outdated/unmaintained #marshallofsound/webpack-asset-relocator-loader which caters for native modules via Webpack. I'm currently working on a PR to fix this but in the meantime you can use my updated fork.
None of the solutions on the web worked for me. What worked is defining electron-gyp output folder as home before electron-rebuild or with electron-forge right after/before dependencies install.
In a terminal:
Windows:
set HOME=C:\Users\YourUser\.electron-gyp
npm i
npm run start <# which resolves to electron-forge start #>
Unix:
$ export HOME=~/.electron-gyp
$ npm i
$ npm run start # which resolves to electron-forge start
I hope it helps to someone

Node error: "SyntaxError: Unexpected token {" at "const {join, basename} = require('path')"

I need to work with an app based on ionic framework v1 and Cordova 7.1, but there is the following problem with Node when running Cordova:
$ cordova -v
/node_modules/cordova/node_modules/npm-normalize-package-bin/index.js:3
const {join, basename} = require('path')
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (node_modules/cordova/node_modules/read-package-json/read-json.js:14:27)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
I installed Cordova with this command:
npm install -g cordova#7.1.0
The project requires the following versions which are installed on my machine:
node -v
v5.12.0
npm -v
3.8.6
ionic -v
1.7.15
grunt --version
grunt-cli v0.1.13
grunt v0.4.5
bower -v
1.8.4
plugman -v
2.0.0
Does anyone have a clue where the problem is? I'm glad for any help.
The problem is that nodejs v5.x doesn't support destructuring, which is used in the line
const {join, basename} = require('path')
You can read more about supported js features in nodejs here, https://node.green/#ES2015-syntax-destructuring--declarations
Cordova depends on "init-package-json" which in turn depends on "read-package-json: 1 || 2".
Now there's been an update to "read-package-json" some months ago which introduces a new dependency to "npm-normalize-package-bin". This package makes use of a syntax construct that's apparently supported not before node 6.0.0.
So, if updating node is not an option (which is recommended, since node 5 - 8 is end-of-life), you may install this (also rather outdated) cordova locally (inside the project folder) and overwrite the read-package-json dependency there by npm i read-package-json#2.0.13.
Edit: Call cordova via npx: npx cordova -v
Thank you all for your helpful inputs to better understand the cause.
Unfortunately, updating node was not an option. In the end, I compared my Cordova installation with a teammate who does not have this problem. The only difference was that his 'cordova/node_modules/npm-normalize-package-bin' was not present where the error is triggered. So I deleted this package from my system to solve the problem.
Maybe this will help somebody else.

Error running npm command on Windows: graceful-fs

I have a ReactJS project and I was trying to use some of the PrimeReact components. At some point, I faced an error (can't remember exactly which one) and I tried to run an older version of NPM in a copy of my main directory.
Now, I get this error every time, even when I run npm command.
I've already tried to delete my node_modules folder, delete my project and clone it back from GitHub and also to reinstall NodeJS several times. I don't know what to do!
I have Windows 10 and I'm using NodeJS v12.16.0.
Thanks to anyone that offers some help
Update: I have never installed gulp. I suppose that maybe some dependency is using it but, because I can't run any npm command, I can't remove them D:
The error:
C:\Users\Carlos>npm
evalmachine.<anonymous>:35
} = primordials;
^
ReferenceError: primordials is not defined
at evalmachine.<anonymous>:35:5
at Object.<anonymous> (C:\Users\Carlos\AppData\Roaming\npm\node_modules\npm\node_modules\npm-registry-client\node_modules\graceful-fs\fs.js:12:1)
at Module._compile (internal/modules/cjs/loader.js:1157:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
at Module.load (internal/modules/cjs/loader.js:1001:32)
at Function.Module._load (internal/modules/cjs/loader.js:900:14)
at Module.require (internal/modules/cjs/loader.js:1043:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\Carlos\AppData\Roaming\npm\node_modules\npm\node_modules\npm-registry-client\node_modules\graceful-fs\graceful-fs.js:3:27)
at Module._compile (internal/modules/cjs/loader.js:1157:30)
It might be an error related with gulp and node v12 conflict. If you have the gulp installed globally in your environment and you can uninstall without problems, you can try it. To help with commands, check if you have the gulp installed, typing this in your command line interface:
gulp -v
Uninstall your version:
npm uninstall -g gulp

Node module-alias Error: Cannot find module '#src/utils/constants'

I'm running mocha tests and I recently upgraded to the newest version of the ask-cli. I ran the tests again and I'm now receiving this module error. I've npm installed src and utils to no avail. From what I've read it's possible module-alias does not support #src paths.
I'm calling this command:
$ ask api simulate-skill -l en-US -t "start my day" -s amzn1.ask.skill.XXXXXXXX-4156-4ca0-b14e-XXXXXXXXXXXX
Update: this seems to be an issue with the ask-cli which uses
const CONSTANTS = require('#src/utils/constants');
The #src should find the source of the node package but this #src is not used in any other packages I could find. All other packages seem to use ../../ so that's likely while module-alias does not find anything bc it doesn't know how to route this new syntax
Does anyone know of this new #src syntax and if there is a npm module for helping route it?
Which worked for ask-cli 1.1.6 but I upgraded to 1.7.2 for new functionality.
Error: Cannot find module '#src/utils/constants'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._resolveFilename (/Users/calebgates/WebstormProjects/AutomatedUtteranceTesting/node_modules/module-alias/index.js:49:29)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/calebgates/WebstormProjects/AutomatedUtteranceTesting/node_modules/ask-cli/lib/commands/init/index.js:1:81)
at Module._compile (module.js:652:30)
at Module.replacementCompile (/Users/calebgates/WebstormProjects/AutomatedUtteranceTesting/node_modules/nyc/node_modules/append-transform/index.js:58:13)
at module.exports (/Users/calebgates/WebstormProjects/AutomatedUtteranceTesting/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
at Object.<anonymous> (/Users/calebgates/WebstormProjects/AutomatedUtteranceTesting/node_modules/nyc/node_modules/append-transform/index.js:62:4)
module.js:549
I solved this by including the ask-sdk in my local project's dependencies.
This is acknowledged bug when ask-cli is installed locally. There are two work-arounds pointed out in the bug report.
Either install ask-cli globally:
$ npm install -g ask-cli
Or install the module-alias package:
$ npm install module-alias
and configure it to look for #src in the ask-cli/lib folder by adding the following to your package.json file:
"_moduleAliases": {
"#src": "./node_modules/ask-cli/lib",
"#root": "./node_modules/ask-cli",
"#test": "./node_modules/ask-cli/test"
}

What's wrong with my typescript compiler? `tsc --version` returns nothing

In Linux Mint, I've installed node and used it to install typescript. With a working typescript installation, tsc --version should return the version number. In my case, nothing is returned at all.
When I run which tsc the result is /usr/local/bin/tsc.
When I run cat /usr/local/bin/tsc the result is:
#!/usr/bin/env node
require('../lib/tsc.js')
When I run find /usr/local -name 'tsc*' the result is:
/usr/local/bin/tsc
/usr/local/lib/node_modules/typescript/bin/tsc
/usr/local/lib/node_modules/typescript/lib/tsc.js
Does that look correct? If so, then any ideas on what else to look at would be appreciated?
Note I also tried running /usr/local/lib/node_modules/typescript/bin/tsc --version and got the same result ie nothing.
In my case on Ubuntu 16.04 the problem was because of I performed sudo apt-get install node-typescript, which delivered me broken tsc. After removing it via apt-get remove and then installing as recommended with npm install -g typescript, it worked fine.
Maybe this will help someone.
I discovered that running node --version returns nothing (but shouldn't) however nodejs --version works (the result being v0.10.25). Reinstalling node didn't fix this. I don't know why this would be the case, as I think I followed the recommended installation procedure.
However, editing file /usr/local/bin/tsc and changing the line:
#!/usr/bin/env node
to
#!/usr/bin/env nodejs
seemed to work. Now tsc --version returns message TS6029: Version 1.6.2 and I'm getting .js files generated when I run make.
I was getting the following error in Ubuntu 16.04.6 :
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'typescript/tsc.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/bin/tsc:2:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
Running : npm install -g typescript didn't resolved the issue.
So, I had to install the latest version of node i.e nvm install <nvm version>
Then with npm install , it fixed the issue.

Resources