Brakko
Brakko

Reputation: 43

npm use local modules

I've just installed the babel-cli module locally to my project but when I run babel test.js in the terminal it outputs that the *command babel is uknown*.

What I figured out is that npm is trying to find the module in my globally installed modules instead of my project modules, how can I fix it?

Sorry for the silly question but I'm not finding a solution.

Upvotes: 0

Views: 797

Answers (2)

elssar
elssar

Reputation: 5871

You can either

  1. Use the babel installed in you project - node_modules/.bin/babel test.js

  2. Add a script in your package.json and run it via npm - npm run <script_name>. npm will use the version of babel installed in your project

Upvotes: 1

atilkan
atilkan

Reputation: 5018

When you run babel. It looks for global npm directory and can't find it there.

2 ways but one is redundant.

  • You can link your local path to global npm directory which is redundant and wont work for the next project. Don't never do this.
  • Or install it globally. That how npm works for now.

There is a discussion on that. And here is a good article. http://www.joezimjs.com/javascript/no-more-global-npm-packages/

Upvotes: 0

Related Questions