how do i fix issue regarding "npm -v" not working? I upgrade to angular 10 and everytime I use terminal this below error - node.js

how do i fix issue regarding "npm -v" not working? I upgrade to angular 10 and everytime I use terminal this below error.
internal / modules / cjs / loader.js: 976
throw err; ^
Error: Cannot find module '../lib/utils/unsupported.js'
Require stack:
-/usr/local / lib / node_modules / npm / bin / npm - cli.js
at Function.Module._resolveFilename(internal / modules / cjs / loader.js: 973: 15)
at Function.Module._load(internal / modules / cjs / loader.js: 855: 27)
at Module.require(internal / modules / cjs / loader.js: 1033: 19)
at require(internal / modules / cjs / helpers.js: 72: 18)
at / usr / local / lib / node_modules / npm / bin / npm - cli.js: 19: 21
at Object. < anonymous > (/usr/local / lib / node_modules / npm / bin / npm - cli.js: 153: 3)
at Module._compile(internal / modules / cjs / loader.js: 1144: 30)
at Object.Module._extensions..js(internal / modules / cjs / loader.js: 1164: 10)
at Module.load(internal / modules / cjs / loader.js: 993: 32)
at Function.Module._load(internal / modules / cjs / loader.js: 892: 14) {
code: 'MODULE_NOT_FOUND',
requireStack: ['/usr/local/lib/node_modules/npm/bin/npm-cli.js']
}
`

Related

Nuxt - wall of errors when installing Sass

I'm not very confident with NPM/CMD-based dev and I'm trying to add Sass to a Nuxt installation.
As per the Sass docs, I did this via
npm install --save-dev node-sass sass-loader
But when I restarted my Nuxt server via yarn dev, I then got this wall of errors, which means very little. I then uninstalled Sass via
npm uninstall node-sass sass-loader
...and I can once again start my Nuxt server without issue. What on earth happened?
ERROR Failed to compile with 64 errors
These dependencies were not found:
* core-js/modules/es6.array.filter.js in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 1 other
* core-js/modules/es6.array.find.js in ./.nuxt/client.js
* core-js/modules/es6.array.from.js in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 1 other
* core-js/modules/es6.array.iterator.js in ./.nuxt/client.js
* core-js/modules/es6.array.map.js in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 1 other
* core-js/modules/es6.array.slice.js in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 1 other
* core-js/modules/es6.date.to-string.js in ./.nuxt/utils.js, ./.nuxt/components/nuxt.js and 1 other
* core-js/modules/es6.function.name.js in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 1 other
* core-js/modules/es6.object.assign.js in ./.nuxt/client.js
* core-js/modules/es6.object.get-own-property-descriptor.js in ./.nuxt/index.js, ./node_modules/ufo/dist/index.mjs
* core-js/modules/es6.object.keys.js in ./.nuxt/client.js, ./.nuxt/components/utils.js and 1 other
* core-js/modules/es6.object.to-string.js in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 2 others
* core-js/modules/es6.promise.js in ./.nuxt/client.js
* core-js/modules/es6.regexp.constructor.js in ./.nuxt/utils.js
* core-js/modules/es6.regexp.match.js in ./node_modules/ufo/dist/index.mjs
* core-js/modules/es6.regexp.replace.js in ./.nuxt/index.js, ./.nuxt/components/nuxt.js and 1 other
* core-js/modules/es6.regexp.search.js in ./.nuxt/utils.js, ./node_modules/ufo/dist/index.mjs
* core-js/modules/es6.regexp.split.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./.nuxt/components/nuxt-build-indicator.vue?vue&type=script&lang=js&, ./node_modules/ufo/dist/index.mjs
* core-js/modules/es6.regexp.to-string.js in ./.nuxt/utils.js, ./.nuxt/components/nuxt.js and 1 other
* core-js/modules/es6.string.ends-with.js in ./node_modules/ufo/dist/index.mjs
* core-js/modules/es6.string.includes.js in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js
* core-js/modules/es6.string.iterator.js in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 1 other
* core-js/modules/web.dom.iterable.js in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 1 other
errors
To install them, you can run: npm install --save core-js/modules/es6.array.filter.js core-js/modules/es6.array.find.js core-js/modules/es6.array.from.js core-js/modules/es6.array.iterator.js core-jerrors 12:15:27 s/modules/es6.array.map.js core-js/modules/es6.array.slice.js core-js/modules/es6.date.to-string.js core-js/modules/es6.function.name.js core-js/modules/es6.object.assign.js core-js/modules/es6.objerrors 12:15:27 ect.get-own-property-descriptor.js core-js/modules/es6.object.keys.js core-js/modules/es6.object.to-string.js core-js/modules/es6.promise.js core-js/modules/es6.regexp.constructor.js core-js/moduleerrors 12:15:27 s/es6.regexp.match.js core-js/modules/es6.regexp.replace.js core-js/modules/es6.regexp.search.js core-js/modules/es6.regexp.split.js core-js/modules/es6.regexp.to-string.js core-js/modules/es6.strierrors 12:15:27 ng.ends-with.js core-js/modules/es6.string.includes.js core-js/modules/es6.string.iterator.js core-js/modules/es6.string.repeat.js core-js/modules/es6.string.starts-with.js core-js/modules/es6.symberrors 12:15:27 ol.js core-js/modules/es7.array.includes.js core-js/modules/es7.object.entries.js core-js/modules/es7.object.get-own-property-descriptors.js core-js/modules/es7.promise.finally.js core-js/modules/ws/modules/es6.arreb.dom.iterable.js
rty-descriptor.js
i Waiting for file changes
es6.regexp.re
core-js/modul
i Memory usage: 809 MB (RSS: 931 MB)
ct.entries.js cor
i Listening on: http://localhost:3000/
WARN Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\DumpStack.log.tmp'
try installing how the nuxt js documents say here
npm install --save-dev sass sass-loader#10 fibers

How to insert the .env into a folder and run the nodemon?

SERVER.JS RESUME DOTENV
const dotenv = require('dotenv-safe');
this.dotenv = dotenv.load();
Problems:
1) I can not run the nodemon if it has only the .env file, it runs only if it contains the .env and .env.example files and I would like to know why and how to correctly match it.
2) How to insert the .env in the /env folder without the problem nodemon?
3) In my start script of package.json is the following "start_dev": "nodemon app/backend/src/start.js", however it is giving the following error:
nodemon app / backend / src / start.js
[nodemon] 1.18.9
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *. *
[nodemon] starting `node app / backend / src / start.js`
consign v0.1.6 Initialized in C: \ Users \ THIAGOSAAD \ Documents \ DEVELOPMENT \ NEORIS \ ALIANSCE \ aliansce-app-analyticals-panel
fs.js: 115
throw err;
^
Error: ENOENT: no such file or directory, open '.env.example'
at Object.openSync (fs.js: 436: 3)
at Object.readFileSync (fs.js: 341: 35)
C: \ Users \ THIAGOSAAD \ Documents \ DEVELOPMENT \ NEORIS \ ALIANSCE \ aliansce-app-analyticals-panel \ node_modules \ dotenv-safe \ index.js: 27: 45)
at new Application (C: \ Users \ THIAGOSAAD \ Documents \ DEVELOPMENT \ NEORIS \ ALIANSCE \ aliansce-app-analyticals-panel \ app \ backend \ src \ config \ server.js: 11: 32)
at-the-object. <anonymous> (C: \ Users \ THIAGOSAAD \ Documents \ DEVELOPMENT \ NEORIS \ ALIANSCE \ aliansce-app-analyticals-panel \ app \ backend \ src \ config \ server.js: 65: 18)
at Module._compile (internal / modules / cjs / loader.js: 688: 30)
at Object.Module._extensions..js (internal / modules / cjs / loader.js: 699: 10)
at Module.load (internal / modules / cjs / loader.js: 598: 32)
at tryModuleLoad (internal / modules / cjs / loader.js: 537: 12)
at Function.Module._load (internal / modules / cjs / loader.js: 529: 3)
at Module.require (internal / modules / cjs / loader.js: 636: 17)
at require (internal / modules / cjs / helpers.js: 20: 18)
at aliasce-app-analyticals-panel \ app \ backend \ src \ start.js: 1: 78)
at Module._compile (internal / modules / cjs / loader.js: 688: 30)
at Object.Module._extensions..js (internal / modules / cjs / loader.js: 699: 10)
at Module.load (internal / modules / cjs / loader.js: 598: 32)
[nodemon] app crashed - waiting for file changes before starting ...
And if I run the nodemon in the C:\Users\username\Documents\DEVELOPMENT\NEORIS\ ALIANSCE\aliansce-app-analyticals-panel\app\ ackend\src directory
It works!
I looked at this line of code - https://github.com/rolodato/dotenv-safe/blob/master/index.js#L27
It tries to read file .env.example but can not find it in the current folder (run pwd to check it)
It might be 3 ways to solve issue
1) Run
cd app/backend/src
nodemon start.js
2) Move files .env, .env.example to parent folder (aliansce-app-analyticals-panel) and then run nodemon app/backend/src/start.js
3) Do not use dotenv-safe at all. Use your own simple script like this one
Just look at this simple example:
https://github.com/olegdovger/pizza-delivery-api/blob/master/lib/env.js (script)
https://github.com/olegdovger/pizza-delivery-api/blob/master/index.js#L1 (how to invoke script)
With help of #OlegDover and yargs, I managed to pass .env file from a different path and use nodemon for hot-reloading during development.
e.g. $ nodemon --watch /path/to/.env server.js --envPath=path/to/.env will pick up changes to .env file and restart deployment.
Example Code
.env
EXAMPLE_HOST=myhost
EXAMPLE_PORT=5566
env.js
/*
* Module dependencies
*/
const fs = require("fs");
const yargs = require("yargs");
/*
* Custom class to update process.env from custom filepath
* Ref: https://github.com/olegdovger/pizza-delivery-api/blob/master/lib/env.js
*/
class Env {
constructor(envPath) {
this.variables = [];
this._setup(envPath);
}
_setup(envPath) {
try {
const data = fs.readFileSync(envPath, {
encoding: "utf-8",
});
const stringArray = data.split("\n");
this.variables = stringArray.map((string) => {
const arr = string.split("=");
return {
name: arr[0],
value: arr[1],
};
});
} catch (err) {
console.error("Unable to load .env;", err);
}
}
load() {
this.variables.forEach((variable) => {
process.env[variable.name] = variable.value;
});
}
}
/*
* Load .env from argv filepath
*/
const argv = yargs.argv;
new Env(argv["envPath"]).load();
/**
* Register
*/
module.exports = {
EXAMPLE_HOST: process.env.EXAMPLE_HOST || "localhost",
EXAMPLE_PORT: Number(process.env.EXAMPLE_PORT) || 12345,
};
server.js
const { EXAMPLE_HOST, EXAMPLE_PORT } = require("./env");
The environment variables can then be loaded/used in the project, having the fallback values if they are not defined in the .env file.
i.e. if EXAMPLE_HOST is not present in .env, this value will default to localhost

Webpack errors related to material-ui

I'm cloning my friend's repo on github
https://github.com/feijihn/todolist_react
with web app built on node.js + react.js + material.ui
then i'm installing requirements with npm:
npm i -S -d
after that i launch server
node server.js
and everything works perfectly, but then i make some changes and try to pack a new bundle.js thru webpack it gives me this error:
webpack --display-detailed-errors
Hash: 396f0bfb9d565b6f60f0
Version: webpack 1.12.12
Time: 1294ms
+ 1 hidden modules
ERROR in ./public/scripts/index.jsx
Module build failed: SyntaxError: /home/ignatif/todolist_react/public/scripts/index.jsx: Unexpected token (91:3)
89 | render: function() {
90 | return (
91 | <Paper className="paperE" zDepth={5}>
| ^
92 | <AppBar
93 | title="Just To-Do. No shit"
94 | iconClassNameRight="muidocs- icovigation-expand-more"/>
at Parser.pp.raise (/home/ignatif/todolist_react/node_modules/babylon/index.js:1425:13)
at Parser.pp.unexpected (/home/ignatif/todolist_react/node_modules/babylon/index.js:2907:8)
at Parser.pp.parseExprAtom (/home/ignatif/todolist_react/node_modules/babylon/index.js:754:12)
at Parser.pp.parseExprSubscripts (/home/ignatif/todolist_react/node_modules/babylon/index.js:509:19)
at Parser.pp.parseMaybeUnary (/home/ignatif/todolist_react/node_modules/babylon/index.js:489:19)
at Parser.pp.parseExprOps (/home/ignatif/todolist_react/node_modules/babylon/index.js:420:19)
at Parser.pp.parseMaybeConditional (/home/ignatif/todolist_react/node_modules/babylon/index.js:402:19)
at Parser.pp.parseMaybeAssign (/home/ignatif/todolist_react/node_modules/babylon/index.js:365:19)
at Parser.pp.parseParenAndDistinguishExpression (/home/ignatif/todolist_react/node_modules/babylon/index.js:827:26)
at Parser.pp.parseExprAtom (/home/ignatif/todolist_react/node_modules/babylon/index.js:713:19)
at Parser.pp.parseExprSubscripts (/home/ignatif/todolist_react/node_modules/babylon/index.js:509:19)
at Parser.pp.parseMaybeUnary (/home/ignatif/todolist_react/node_modules/babylon/index.js:489:19)
at Parser.pp.parseExprOps (/home/ignatif/todolist_react/node_modules/babylon/index.js:420:19)
at Parser.pp.parseMaybeConditional (/home/ignatif/todolist_react/node_modules/babylon/index.js:402:19)
at Parser.pp.parseMaybeAssign (/home/ignatif/todolist_react/node_modules/babylon/index.js:365:19)
at Parser.pp.parseExpression (/home/ignatif/todolist_react/node_modules/babylon/index.js:329:19)
at Parser.pp.parseReturnStatement (/home/ignatif/todolist_react/node_modules/babylon/index.js:2106:26)
at Parser.pp.parseStatement (/home/ignatif/todolist_react/node_modules/babylon/index.js:1894:19)
at Parser.pp.parseBlockBody (/home/ignatif/todolist_react/node_modules/babylon/index.js:2294:21)
at Parser.pp.parseBlock (/home/ignatif/todolist_react/node_modules/babylon/index.js:2275:8)
at Parser.pp.parseFunctionBody (/home/ignatif/todolist_react/node_modules/babylon/index.js:1130:22)
at Parser.pp.parseFunction (/home/ignatif/todolist_react/node_modules/babylon/index.js:2406:8)
at Parser.pp.parseFunctionExpression (/home/ignatif/todolist_react/node_modules/babylon/index.js:764:17)
at Parser.pp.parseExprAtom (/home/ignatif/todolist_react/node_modules/babylon/index.js:726:19)
at Parser.pp.parseExprSubscripts (/home/ignatif/todolist_react/node_modules/babylon/index.js:509:19)
at Parser.pp.parseMaybeUnary (/home/ignatif/todolist_react/node_modules/babylon/index.js:489:19)
at Parser.pp.parseExprOps (/home/ignatif/todolist_react/node_modules/babylon/index.js:420:19)
at Parser.pp.parseMaybeConditional (/home/ignatif/todolist_react/node_modules/babylon/index.js:402:19)
at Parser.pp.parseMaybeAssign (/home/ignatif/todolist_react/node_modules/babylon/index.js:365:19)
at Parser.pp.parseObjPropValue (/home/ignatif/todolist_react/node_modules /babylon/index.js:1021:99)
I have material-ui installed and i can't find any dependency problems myself.
My friend's webpack packs everything nicely and don't give any error. What can cause this?
The repo you provided work if you type :
npm install
webpack
node server.js

What's wrong with my babel?

I have installed babel with npm install -g babel-cli and tested it with babel-node --version. The output is 6.2.0.
Then I tested it like below.
C:\Users\xuhang\Documents\work\CDT\cdt3.0\babel>babel-node
> console.log([1,2,3].map(x => x * x))
repl:1
console.log([1, 2, 3].map(x => x * x));
^^
SyntaxError: Unexpected token =>
at Object.exports.runInThisContext (vm.js:73:16)
at _eval (C:\Users\xuhang\AppData\Roaming\npm\node_modules\babel-cli\lib\_b
abel-node.js:102:26)
at REPLServer.replEval (C:\Users\xuhang\AppData\Roaming\npm\node_modules\ba
bel-cli\lib\_babel-node.js:187:14)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:279:12)
at REPLServer.emit (events.js:107:17)
at REPLServer.Interface._onLine (readline.js:214:10)
at REPLServer.Interface._line (readline.js:553:8)
at REPLServer.Interface._ttyWrite (readline.js:830:14)
>
Could you tell me what's wrong with console.log([1,2,3].map(x => x * x))?
Another simliar issue is below. It's so hard for me to learn babel, the initial test all failed.
What's inside the directory source is the example.js within the official sample provided by React below.
https://facebook.github.io/react/docs/tutorial.html
C:\Users\xuhang\Documents\work\CDT\cdt3.0\babel>babel source/ --watch --out-dir
build/
SyntaxError: source/example.js: Unexpected token (17:6)
15 | var rawMarkup = marked(this.props.children.toString(), {sanitize: tru
e});
16 | return (
> 17 | <div className="comment">
| ^
18 | <h2 className="commentAuthor">
19 | {this.props.author}
20 | </h2>
You've forgotten to create a .babelrc file. Pre 6.x version of Babel contained a few presets for Babel to transpile code out of the box, in 6.x it does not so you need to install the presets you want and in your case you need two: babel-preset-es2015 and babel-preset-react.
After you've installed them both npm install babel-preset-es2015 babel-preset-react add them to your .babelrc file
{
"presets": ["es2015", "react"]
}

babel-node not recognizing jsx <

I am trying to run some code that uses React and JSX using babel-node, which is part of the babel-cli. To the best of my knowledge the code is correct and I am using babel-node as expected, but hopefully someone can provide more insight.
The following error is generated.
(!535)-> babel-node server.js
/Users/eprouty/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:520
throw err;
^
SyntaxError: /Users/ep/git/dgcastle/server.js: Unexpected token (60:51)
58 | res.status(302).redirect(redirectLocation.pathname + redirectLocation.search)
59 | } else if (renderProps) {
> 60 | var html = ReactDOM.renderToString(<RoutingContext {...renderProps} />);
| ^
61 | var page = jade.renderFile('views/index.jade', {html: html});
62 | res.status(200).send(page);
63 | } else {
at Parser.pp.raise (/Users/ep/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babylon/lib/parser/location.js:24:13)
at Parser.pp.unexpected (/Users/ep/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babylon/lib/parser/util.js:91:8)
at Parser.pp.parseExprAtom (/Users/ep/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babylon/lib/parser/expression.js:507:12)
at Parser.pp.parseExprSubscripts (/Users/ep/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babylon/lib/parser/expression.js:260:19)
at Parser.pp.parseMaybeUnary (/Users/ep/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babylon/lib/parser/expression.js:240:19)
at Parser.pp.parseExprOps (/Users/ep/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babylon/lib/parser/expression.js:171:19)
at Parser.pp.parseMaybeConditional (/Users/ep/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babylon/lib/parser/expression.js:153:19)
at Parser.pp.parseMaybeAssign (/Users/ep/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babylon/lib/parser/expression.js:120:19)
at Parser.pp.parseExprListItem (/Users/ep/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babylon/lib/parser/expression.js:966:16)
at Parser.pp.parseCallExpressionArguments (/Users/ep/.nvm/versions/v5.0.0/lib/node_modules/babel-cli/node_modules/babylon/lib/parser/expression.js:336:20)
I can provide additional code snippets if that would help but the offending block is already included in the error message. Thanks for any insight you can provide!
If you are running version 6.x of babel, you need to use the babel react preset (as stated here).
If you are using babel 6.x, you will need to install the relevant preset/plugins. To get started, you can run npm install -g babel babel-preset-react and then run babel --presets react --watch src/ --out-dir lib/. For more information: check out the babel 6 blog post

Resources