user841760
user841760

Reputation: 359

Npm module not found

I'm running an Angular app built with Grunt and using Bower and NPM.

I tried installing my npm module locally. The files are in the main app directory in node_modules folder.

The module docs ask me to load the module with <script type="text/javascript" src="node_modules/moment/moment.js"></script>, but I get 404.

Am I missing something? Do I have to tell Grunt that I want these NPM modules?

Upvotes: 2

Views: 69687

Answers (4)

Mansimar anand
Mansimar anand

Reputation: 17

I faced the same issue just install the package globally and save at the end.

Like:

npm install -g <package> --save

Even the above doesn't work then use -f / --force at the end to force install.

Upvotes: 0

Manuel Hernandez
Manuel Hernandez

Reputation: 524

If you installed your npm packages locally then your node_modules folder should found at the root of your project.

If you installed all your packages globally you may not see an npm_modules folder in your project.

To see where your global modules are located you can run

npm list -g 

Upvotes: 0

Sai Pavan
Sai Pavan

Reputation: 183

Basically, npm is the package manager for all the javaScript frameworks such as Nodejs, angularjs etc. npm should be installed globally in the machine.You can install it from https://nodejs.org/en/ .

Next,you need check for the package.json file in your project.

If there is a package.json already existing in your project folder, then from command line you need to go to your project folder and type npm start.

If package.json file does not exist, then in the command line type npm init,then there will be a package.jsonfile created in your project folder.Then edit the package.json . and add the node packages into the package.json as similar way to this

{
  "name": "shoppingkart",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www" //If you have any scripts.
  },
  "dependencies": {
    "mongoose": "^4.9.0",  // here you should have all your node_modules listed
    "passport": "^0.3.2",
    "stripe": "^4.15.1"
  }
}

if you are not able to add the dependencies to json file, there is also another way to do it. just go to your project directory in the command line and type

npm install --save grunt // And you need to do for all the node_modules, by replacing the **grunt**.

Automatically the dependency will be added to your package.json file.

Upvotes: 1

citivin
citivin

Reputation: 686

Can you provide more information on what your app is built with? If node serves your app, you need to make the directory you link to public. Assuming you're using express, this would look something like this in your app.js file:

app.use('/node_modules', express.static(__dirname + '/node_modules/moment/moment.js'));

Edit: Or if you just want to make it work, try to load moment.js from CDN like this:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>

Link to moment on CDN

Upvotes: 1

Related Questions