npm run dev not working with sveltekit/vite project - npm

whenever i run this command: npm run dev, I get the following error. this is a sveltekit and vite (which i'm very new to) project.
> my-app#0.0.1 dev
> vite dev
failed to load config from /home/believe/Documents/my-app/vite.config.js
error when starting dev server:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '#sveltejs/kit' imported from /home/believe/Documents/my-app/vite.config.js.timestamp-1659118538332.mjs
at new NodeError (node:internal/errors:363:5)
at packageResolve (node:internal/modules/esm/resolve:698:9)
at moduleResolve (node:internal/modules/esm/resolve:739:18)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:853:11)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:73:40)
at link (node:internal/modules/esm/module_job:72:36)

IMHO, using / switching-to the latest version of node should ideally resolve this issue. I had faced this error, and switching to the latest version of node is what worked for me.
I have found that installing the nvm (node version manager) cli package is one of the best and handy ways to address and handle such situations. This is because, it will let you install and manage multiple versions of node, so that you can switch node versions, between projects, as needed per relevant dependencies.
For eg., in this case, I would just say nvm use latest in the project cli, and nvm will switch to the latest node version (if/where installed ==> node v18.7.0 w/ npm 8.15.00 as of now, for me, for eg. ).
At that, nvm ls lists all the installed node versions on that system/ environment, and points to the one in use at the moment. Very handy!
More info on nvm here: http://nvm.sh/
[* Since you have not mentioned the OS/ENV and Terminal etc., I can not unfortunately (at this time) share specific install instructions, and am hence pointing to the nvm git. Hope you understand. :) ]
Hope this helps; have a nice day! :)

Related

NVM for windows is failing when using npm prestart scripts

When I try to run my project, doing npm start I am getting the below. We have this chain in our project since some repos are using different node versions. I have nvm-windows 1.1.9 latest installed. I have tried a machine recycle, re-installing nvm for windows, deleting the packages and modules and much more. Whats interesting is that when I remove the prestart script and am on the required version by doing nvm use 18.4.0 this works, also when I add back in the prestart script and use for instance nvm use 12.22.12 the prestart script executes fine when running npm start and the version changes t0 18.4.0 with no issue, but if I stop the project and start it again it fails with the below and either I need to remove the prestart script or change to a different version. I am not understanding how this could be.
prestart
nvm install 18.4.0 && nvm use 18.4.0
This is not the package you are looking for: please go to http://nvm.sh

React Native Fails To Start Server With Error In #react-native-community/cli/build/commands/doctor/healthchecks/index.js

I just created a brand new React Native project, and I can't get it to run. The server always fails on the following:
node_modules/react-native/node_modules/#react-native-community/cli/build/commands/doctor/healthchecks/index.js:48
} catch {}
^
SyntaxError: Unexpected token {
The only thing I've found on this issue is this thread, which ends with people saying to post this question on Stackoverflow, hence why I'm here. I've tried the usual: upgrading node versions, removing node_modules and reinstalling, restarting my machine, all to no avail. I even delved into the code to see if I could figure out what's going on, but nothing jumped out at me.
My hope is that others have run into this with new React Native projects and that someone can help me resolve it. Any suggestions are welcome. Thanks!
Sigh.... Well after struggling with this for a day I found the workaround was to run npx react-native start in one console and then run npx react-native run-ios in another. I was just trying to do the latter by itself (which always worked in the past), and I guess that doesn't work anymore.
Probably your node and/or npm version is to old. Check by npm -v and node -v and update to latest version, or suggesting by react-native crew in dependencies from node site. Or if you use nvm try:
nvm install 16.14.0 && nvm alias default 16.14.0 && nvm use 16.14.0
Note that, this is for specific version. For latest, type:
nvm install --lts --latest-npm
nvm use x.x.x //latest installed version
This problem is due to node version. Upgrade your node verion above 12. It will solve the problem.
Use can either use nvm or directly install the node
if you are using android studio start it with command line
like this cd /path/to/android-studio/bin
then studio.sh make sure its executable

npx from command line does not find imports?

I'm trying to run a simple hello.ts script from command line. This works if the script has no dependencies:
npx ts-node hello.ts
But as soon as I start adding some dependencies...
import _ from 'lodash';
console.log('hello');
It fails:
Cannot find module 'lodash' or its corresponding type declarations.
It keeps failing even if I install the dependencies globally. So how do I tell npx (or ts-node for that matter) to consider globally installed dependencies?
Update
Using Node 16.9.1 (upgraded via Version Lens). The error seems to have disappeared after uninstalling/reinstalling the imported libraries a few times.
If you're using npm >=1.0, you can use npm link to create a local link to a package already installed globally. (Caveat: The OS must support symlinks.)
IE: npm install -g lodash && npm link lodash
However, this doesn't come without its problems.
npm link is a development tool. It's awesome for managing packages on your local development box. But deploying with npm link is basically asking for problems, since it makes it super easy to update things without realizing it.
As an alternative, you can install the packages locally as well as globally.
For additional information, see:
https://nodejs.org/en/blog/npm/npm-1-0-link/
https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/
Are you using the n package by any chance? I used n to change from a newer version of node (16.2.0) to an older version of node (12.13.0), ran npm i and npx failed with a different error.
Using n to change back to 16.2.0 seems to have resolved the issue so I'm thinking perhaps it was an issue with package-lock.json or such

WebStorm can't find npm although it is installed via nvm

WebStorm can't find npm although it is installed via nvm.
EDIT: As I found the answer myself I will post below, hoping that others find this helpful as well.
As I had installed node via multiple ways, e.g. via homebrew AND nvm, the trick is to select the node version that you used to install npm with. In my case that is nvm.
Different node installations:
nvm selected as node interpreter, offering the npm option:

How can I install NODE_MODULE_VERSION 46

How can I install a Node.js version using NODE_MODULE_VERSION 46? I keep running into a NODE_MODULE_VERSION mismatch, and recompiling hasn't helped so switching node versions might be easier.
Basically, I keep coming across this:
Warning: The module '/home/cwaugh/workspaces/myproject/build/Release/addon.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 46. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`). Use --force to continue.
So far, I've tried using n to change to different versions (one of my dependencies requires 4.9.1 or below), but that doesn't seem to change the NODE_MODULE_VERSION as recognized by the warning.
I've also tried recompiling:
I've tried deleting node_modules and running npm install again. (this error looks like it's coming from the project root, but it never worked for anything in the node_modules folder either)
node-gyp configure --target=4.9.1 && node-gyp build --target=4.9.1. I got the idea from here, and hoped I'd have better luck than mxcd.
node-pre-gyp rebuild. I saw this, and thought it might work for me.
This works on another, older computer running a vagrant image. Unfortunately, vagrant isn't working on the new computer either, so I've been trying from scratch. Sometimes, I wonder if it's because I'm using Ubuntu 18.04. The server's can't seem to go past 16.04 when they run our docker image.
I GOT IT!
It turns out I was getting different versions from node and nodejs
$ node --version
v4.9.1
$ nodejs --version
v8.10.0
I upgrade to node v8.10.0, redo everything, and the error's gone!
sudo npm install -g n
sudo n 8.10.0
rm -rf node_modules
npm install
node-gyp clean
node-gyp configure
node-gyp build
grunt build
grunt start
# No more NODE_MODULE_VERSION error
I tried uninstalling nodejs (since this it's been replaced by just "node"), but node-grunt-cli requires it. I'm guessing that grunt uses nodejs instead of node to check its version, causing the error. The Ubuntu repositories have Grunt v0.4.5, while Grunt stable is at v1.0.3, so it's possible a newer version of grunt would also solve this problem.
The solution didn't work for me since I had just one node version (10).
What was happening in my project, was that the package.json was pulled from the remote repository with an old version package.
At the moment of installing node modules locally (using yarn), it would download up-to-date dependencies, creating incompatibility.
After trying several solutions, what finally worked for me was picking the specific package that was giving me headache (login-funcs-nodejs) and run:yarn upgrade login-funcs-nodejs --latest