Deploy fails with "Error: Can't find npm module" in Meteor Galaxy - node.js

I tried to deploy to Meteor Galaxy and it didn´t work at all, although everything seems to be working on localhost.
At first, my app was uploaded, but than failed to start. At least, the containers start right now, but than my App is crashing. I think it is a systematic fail within my app structure. Perhaps some npm dependencies are missing in package.json or I need to debug some npm installations?
I don´t think that I have understood exactly how npm is working within Meteor, which dependencies I need to have or what I have to import/require to use npm packages correctly. The meteor docs did not help.
Here are my error logs:
Note: you are using a pure-JavaScript implementation of bcrypt.
While this implementation will work correctly, it is known to be
approximately three times slower than the native implementation.
In order to use the native implementation instead, run
meteor npm install --save bcrypt
in the root directory of your application.
/app/bundle/programs/server/node_modules/fibers/future.js:280
throw(ex);
^
Error: Can't find npm module 'meteor/browser-policy-common'. Did you forget to call 'Npm.depends' in package.js within the 'modules-runtime' package?
at Object.require (/app/bundle/programs/server/boot.js:230:17)
at makeInstallerOptions.fallback (packages/modules-runtime.js:641:18)
at require (packages/modules-runtime.js:234:16)
at meteorInstall.imports.startup.server.browser-policy.js (imports/startup/server/browser-policy.js:1:32)
at fileEvaluate (packages/modules-runtime.js:333:9)
at require (packages/modules-runtime.js:228:16)
at meteorInstall.imports.startup.server.index.js (imports/startup/server/index.js:1:66)
at fileEvaluate (packages/modules-runtime.js:333:9)
at require (packages/modules-runtime.js:228:16)
at meteorInstall.server.main.js (server/main.js:1:14)
at fileEvaluate (packages/modules-runtime.js:333:9)
at require (packages/modules-runtime.js:228:16)
at /app/bundle/programs/server/app/app.js:3668:1
at /app/bundle/programs/server/boot.js:338:34
at Array.forEach (native)
at Function._.each._.forEach (/app/bundle/programs/server/node_modules/underscore/underscore.js:79:11)
It does not matter which module is missing, it seems to be that Galaxy can´t find any of the used npm modules. Before that try, I had the same error with another npm module. Than I just deleted the Npm.require of that module in my code. Now, I have the same error, just with another module.
I think I missed something during the local usage of npm. I am a complete beginner. Everything worked fine locally and now I can´t bring it online. I am using Windows.

It was a general issue, because I never used the --save flag when adding npm packages and therefore had no dependencies of them in my package.json. I removed node_modules and runned meteor npm install --save for every npm package and the error had been gone (additionally I removed the browser-policy package for other reasons).

Related

Issue with NPM start ( React)

I have just tried to view an old application of mine using npm start but it wont load keep getting the error.
Cannot find module 'C:\Users\Team Knowhow\development\Punk-API\node_modules\react-scripts\bin\react-scripts.js.
I tried creating a new react app and NPM start works fine so have no idea what the issue is with my old react app and why NPM start does not work.
Have you installed dependencies first using npm install.
If done already, try removing node_modules folder and installing dependencies again.
Make sure you have installed all dependencies including react-scripts!
You've to ensure that all the dependencies that your application is using is mentioned in the correct manner with their correct version in your pacakage.json file. And if that looks alright then run
npm i
or
npm install
This command will download all the dependencies that are mentioned in your package.json file.

How to build node.js projects against local versions of the dependencies?

I've been trying to build a relatively complex node.js project (https://github.com/edrlab/thorium-reader/) against local versions of some dependencies.
I can build and run the project with the non-local dependencies without problems.
I've tried different "routes", such as adding the dependencies using npm install --save <path-to-dependency> or just adding a file:<path-to-dependency> reference to the package.json file. I've checked out the exact versions of each dependency.
npm install doesn't show any errors.
Now when I run npm run start I get type errors that don't quite understand, such as:
Argument of type 'import("~/repositories/thirdparty/thorium/r2-opds-js/dist/es6-es2015/src/opds/opds2/opds2-facet").OPDSFacet'
is not assignable to parameter of type
'import("~/repositories/thirdparty/thorium/thorium-reader/node_modules/r2-opds-js/dist/es6-es2015/src/opds/opds2/opds2-facet").OPDSFacet'.
Types of property 'Links' are incompatible.
Does anyone have a hint for me what I am doing wrong here ?
I'm using node.js version 17.2.0 and npm version 8.2.0.
Best,
N
Ok, after fiddling around for hours I found that using npm link does the trick. Not sure what the differences are, npm install didn't work at all, neither did putting the references in package.json.
That is, go to the dependency's repository, run npm link, build the dependency as a module, THEN go to the main repository and run npm link <dependency> --save.
Now the build process works.
Not sure why there are the two different method, one of which doesn't work a all in this case.

Do I need to install dependencies one-by-one? (and if so, why?)

I'm porting a node/Express app to Heroku, and it keeps crashing. The log first said, "Error: Cannot find module 'mongoose'" I then (re-)installed mongoose. Then it crashed with "Error: Cannot find module 'moment'"
I require mongoose, moment, etc. in my app. Isn't npm install by itself supposed to take care of the dependencies, or do I additionally have to add all these dependencies, one-by-one, to the package.json file, in addition to npm install? Tks!
In the older version of NPM (5.0.0 or earlier), you had to add --save as a flag to the npm install as:
npm i package-name --save
And it would add it to your package.json. As of 5.0.0 and later, it automatically adds it to the package file.
To answer your question, yes, you will have to add them one at a time for now. And keep in mind what I said before, because if you are using an older version of NPM, make sure you use --save when you are installing so you don't have to do extra work :-)

Laravel 5.5 Webpack dependency was not found

Related SO question: npm - package.json override main field (I tried to do something like this using the webpack.mix.js but it didn't work).
I have a Laravel 5.5 application with npm v5.6.0 and node v9.4.0 (I'm thinking that this maybe is an npm/node version issue, but I don't have an environment to test with older versions ATM). Everything is working fine and I'm working this app for a while now and I've installed some node modules and used bootstrap.js and app.js to require/import npm modules, but it seems there is a problem with the bootstrap-treeview; I've spent more than 2 hours to try and make webpack compile with this module with no luck; I always get that error after npm run dev:
ERROR Failed to compile with 1 errors
This dependency was not found:
bootstrap-treeview in ./resources/assets/js/bootstrap.js
I tried to use both require and import inside bootstrap.js and I have even tried an other available module webpack-bootstrap-treeview which it seems that it doesn't have bower dependency:
//import "~/node_modules/bootstrap-treeview";
//require("bootstrap-treeview");
//import "bootstrap-treeview";
//import "~/node_modules/webpack-bootstrap-treeview";
//require("webpack-bootstrap-treeview");
import "webpack-bootstrap-treeview";
bootstrap-treeview: https://www.npmjs.com/package/bootstrap-treeview
webpack-bootstrap-treeview: https://www.npmjs.com/package/webpack-bootstrap-treeview
I know I can just use laravel-mix to compile the js files directly to the app.js and I will probably do, but I want to have my modules organized and I'd like to find the culprit on this issue.
EDIT
I've also tried to delete the node_modules directory then npm install and even npm cache clear, nothing worked for the webpack to compile without that error.
Looks like there are some misnamed files. Renaming the bootstrap-treeview files in node_modules\bootstrap-treeview-2\dist to bootstrap-treeview-2 allows webpack to successfully complete. Oh, and I installed the bootstrap-treeview-2 package because bootstrap-treeview has been archived.

Error with 'babel-runtime' while trying to serve a Meteor app

I have recently been getting off the ground with Meteor and React. I followed the tutorial on the Meteor website with no problem.
Then I tried creating another project, trying to follow another tutorial (for an older version of Meteor). Somewhere along the line, Meteor started throwing up obscure errors. After trying to start fresh again, I ended up reinstalling Meteor and it stopped complaining.
However, I'm getting the same problems, again. Specifically, after creating a brand new project:
meteor create myproject
cd myproject
meteor
The server throws up the following error:
[...]
W20161109-03:53:42.862(1)? (STDERR) Error: The babel-runtime npm package could not be found in your node_modules
W20161109-03:53:42.862(1)? (STDERR) directory. Please run the following command to install it:
W20161109-03:53:42.863(1)? (STDERR)
W20161109-03:53:42.863(1)? (STDERR) meteor npm install --save babel-runtime
[...]
I do what I'm told and attempt to install babel-runtime package. The server manages to successfully get off the ground, but it then throws up the following error at run-time:
Uncaught Error: Cannot find module 'babel-runtime/helpers/slicedToArray'
at Function.require.resolve
This is all still working off a freshly created project, with no extra packages installed or code changed. I have tried looking online for solutions but, while there are lots of references to bugs that have been fixed, I haven't found anything. A couple of (questions)[Babel - Error: Cannot find module 'babel-runtime/helpers/typeof' on StackOverflow have suggested the following:
Reinstalling the NPM modules
rm -rf node_modules
meteor npm install
Updating NPM
meteor npm update -g npm
I am using Meteor 1.4.2, NPM 3.10.9, Ubuntu 16.04.1.
I was having the same issue. After a little digging, found this: https://github.com/meteor/meteor/issues/8019
* Installing the `babel-runtime` npm package in your application
`node_modules` directory is now required for most Babel-transformed code
to work, as the Meteor `babel-runtime` package no longer attempts to
provide custom implementations of Babel helper functions.
Consider trying it out by using the latest release candidate (not officially released yet):
meteor update --release 1.4.2.1-rc.1
And then:
meteor npm install --save babel-runtime
After upgrading to 1.4.2.1-rc.1 (and then subsequently upgrading to 1.4.2.1 this morning 11/9), the error was resolved.
Try adding package.json file inside your project directory and then run
meteor
npm install --save babel-runtime
in the command line.
You may have whitespace in your project name. All that you have to do is create another project without whitespace in the name. I know that it's quite difficult to detect the cause from the error message, but it is what it is.
I recently faced this issue with meteor 1.11.1 and the solutions here did not work. Turns out I had whitespaces in my project name (Ghughu Server V2) and all I had to do is create another one without the spaces (GhughuServerV2).
P.S. It works fine even if you have whitespace in the path to your project, you just can't have whitespace in the project name. Also, just renaming the directory doesn't work. Either you have to create a brand new project or change some configuration inside (which seems impractical if you're working in a newly created project).

Resources