Error received when initializing a ViteJS app - npm

When I run the command below in Gitbash:
$ npm init #vitejs/app
I recevice the following error:
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
#vitejs/create-app is deprecated, use npm init vite instead
C:\Users\me\AppData\Local\npm-cache\_npx\9c7583f20b80c4d1\node_modules\#vitejs\create-app\index.js:43
require('create-vite')
^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\me\AppData\Local\npm-cache\_npx\9c7583f20b80c4d1\node_modules\create-vite\index.js from C:\Users\me\AppData\Local\npm-cache\_npx\9c7583f20b80c4d1\node_modules\#vitejs\create-app\index.js not supported.
C:\Users\me\AppData\Local\npm-cache\_npx\9c7583f20b80c4d1\node_modules\create-vite\index.js is treated as an ES module file as it is a .js
file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename C:\Users\me\AppData\Local\npm-cache\_npx\9c7583f20b80c4d1\node_modules\create-vite\index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\Users\me\AppData\Local\npm-cache\_npx\9c7583f20b80c4d1\node_modules\create-vite\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at Object.<anonymous> (C:\Users\me\AppData\Local\npm-cache\_npx\9c7583f20b80c4d1\node_modules\#vitejs\create-app\index.js:43:1) {
code: 'ERR_REQUIRE_ESM'
}
npm ERR! code 1
npm ERR! path C:\Users\me\Desktop
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c C:\Users\me\AppData\Local\Temp\npx-ee21ed07.cmd
Could anyone please help me?

Try this instead:
$npm create vite#latest
Further Documentation
GitHub Related Issue

Worked for me. I follow a website tutorial online (https://www.youtube.com/watch?v=Q7AOvWpIVHU).
I got stuck at step 1.
vscode/app> npm init #vitejs/app
I used vscode/app>npm create vite#latest
Now I can continue, don't know if I will be able to complete the entire tutorial, but for now, it fixes the problem.
If you recommend another way to make an website with 3D content, let me know.

Related

What is the correct way of installing firebase-tools (a npm package) in NixOS/Nix?

I am watching this Udemy course on Firebase. The course is a bit dated, initially made maybe 6 years ago.
At some point the author indicates how to use firebase CLI, hence he indicates the command:
~/projects/chatlive]$ npm install -g firebase-tools
I added sudo to avoid permission problems:
~/projects/chatlive]$ sudo npm install -g firebase-tools
Unfortunately, this error message is retrieved:
npm WARN checkPermissions Missing write access to /nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules
npm ERR! code EROFS
npm ERR! syscall access
npm ERR! path /nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules
npm ERR! errno -30
npm ERR! rofs EROFS: read-only file system, access '/nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules'
npm ERR! rofs Often virtualized file systems, or other file systems
npm ERR! rofs that don't support symlinks, give this error.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-07-28T15_33_55_544Z-debug.log
I am using NixOS and this is my config file. Since the error message mentions the nix/store I thought it could be related.
Usually, I install things in NixOS changing my configuration.nix and doing sudo nixos-rebuild switch. But I thought it would not be necessary to do it considering npm was managing the installation.
Searching on Nix packages, I can see firebase-tools: link. Now, it seems that tweaking the config file is the way...
In situations like this, what is the best practice?
Should I force trying to install via npm (how?)? Should I go for a new generation of NixOS and a full system rebuild just because of this package?
Is there another possible path? Am I missing something?
Thanks.
If you just want to play around with firebase-tools in a development environment, create a shell.nix file in your working directory and add the following lines:
{ pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
nativeBuildInputs = [ pkgs.nodePackages.firebase-tools ];
}
Then run nix-shell to start a shell with firebase-tools included. This is considered best practice for local development environments, see https://nixos.wiki/wiki/Development_environment_with_nix-shell .
If you want to try out packages not in nixpkgs repo you should use npm and install a package locally (without -g ). See https://nixos.wiki/wiki/Node.js#Using_npm_install_-g_fails.

Using npm link returns error "Not Found - GET https://registry.npmjs.org/"

I am trying to link a local dependency of scss styles to a project using npm link. Following the docs I run npm link in the dependencies directory, which tells me:
/usr/local/lib/node_modules/xxx/xyz -> /xxx/xxx/xxx/xxx/xxx/xyz
The I got to my project directory and run npm link xyz but it give the error:
npm ERR! 404 Not Found - GET https://registry.npmjs.org/xyz - Not found
So it is not finding the symlink and searching npm.
I have read that this can be caused by using nvm with different versions of node but this is not the case for me.
How can I successfully link the package?
You can link the package manually:
pacakge.json
"package": "package#*"
Project that requires the dependency
create a symbolic link to the local dependency
cd node_modules
ln -nfs ../relative/path/to/local/package

npm access ls-collaborators is not reading from the custom registry in .npmrc

I have a custom .npmrc file as follows
#foo:registry=https://gitlab.com/api/v4/packages/npm/
// This works and it returns the latest dist tag from the registry as configured in .npmrc
npm view --json #foo/my-package dist-tags
// This fails with a 404
npm access ls-collaborators #foo/my-package
// npm ERR! 404 Not Found - GET https://registry.npmjs.org/-/package/%40foo%2Fmy-package/collaborators?format=cli - Package not found
Some more context:
I am trying to publish an npm package to a private package registry on gitlab using the np module. These commands seem to be executing as part of one of its steps for user authentication.
What am I missing?
Make sure "private": true is in your package.json file. I was running into a similar problem as you, and adding this fixed it for me.

ERROR TypeError: Cannot read property 'version' of undefined Vue.js

When I run npm start
I get
ERROR TypeError: Cannot read property 'version' of undefined
TypeError: Cannot read property 'version' of undefined
This happens after I have run
npm install
I tried to solve the issue by running npm -g install npm#version but instead it gave me this error
npm ERR! code ETARGET
npm ERR! notarget No matching version found for npm#version.
Did you just upgrade your dependencies directly from 3.0?
In v4 eslint is required as a dependency of the project itself.
So npm install --save-dev eslint#4 may fix the warning.
From my experience it may happen if there is import of package.json in one of your project's files, but with incorrect path.
Usually, some build related configurations use version property of the package.json.
It is hard to pinpoint the exact issue, since no specifics provided.
First, I'd search stack trace of the error to locate which file is requesting package.json. Global project search for .version should help to find the issue as well.
If you still unable to locate the issue, please, add full error stack trace.

npm run cannot run an script found in node_modules/.bin/___

I installed sequelize-cli:
npm install sequelize-cli --save
I have only installed it locally, not globally. My local project is at C:/git/craft
I try to execute it by typing sequelize-cli, but this doesn't work; I forget I must type node_modules/.bin/sequelize-cli
I want to use npm run sequelize-cli, expecting this will be a shortcut. The npm-run-script documentation says:
In addition to the shell's pre-existing PATH, npm run adds
node_modules/.bin to the PATH provided to scripts. Any binaries
provided by locally-installed dependencies can be used without the
node_modules/.bin prefix
And yet, when I try to run the script:
"scripts": {
"sequelize-cli":"sequelize-cli"
},
The result fails:
NND#usrem-nnd MINGW64 /c/git/craft (master)
$ npm run sequelize-cli -- --help
> craft#0.0.0 sequelize-cli C:\git\craft
> sequelize-cli "--help"
'sequelize-cli' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Windows_NT 10.0.16299
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "sequelize-cli" "--" "--help"
I couldn't find similar questions/issues online (specifically re: node_modules/.bin/____)
Some Github issues mention that yarn should work, (but also say that npm should work as I expect!.) As a workaround I will just install sequelize-cli globally. I can install sequelize-cli globally, but then running sequelize-cli still produces "command not found". This led me to see my silly mistake...
I had the same question as you. You may have the same problem
Finally, I found it's caused by my project folder has invalid letter.
Change your project folder name and try again.
Ensure you are referencing a script that exists! I wasn't! In fact, npm run was just revealing the obvious problem: the script sequelize-cli doesnt exist anywhere on the computer!
... The script is called sequelize, even though it comes from a project called sequelize-cli. package.json "scripts" value will determine which scripts can be run; the correct package.json should map the script "sequelize" to the nodejs command sequelize:
"scripts": {
"start": "node ./bin/www",
"sequelize":"sequelize"
},
npm run sequelize now works...
My mistake... this answer can be deleted if it's unhelpful.