Jankapunkt
Jankapunkt

Reputation: 8423

Meteor can't find local npm module

I am developing some npm packages parallel to my Meteor application.

The first one is finished and it's tests and build are running without errors.

I want to install my package (mypackage) in my meteor project (myproject) by using a local path:

cd myproject
meteor npm install --save ../lib/mypackage

Note, that it exists in a lib folder outside of the Meteor project. This seems to install the package, as it outputs

+ [email protected]
added 1 package in 12.475s

When looking into the node_modules folder it also exists, but it only as a (soft?) link:

cd node_modules && ls -la | grep mypackage
lrwxr-xr-x    1 user  group     22 26 Jan 11:02 mypackage -> ../../lib/mypackage

Here comes the problem: When running my project or my tests I get an error for the following line:

import { SomeClass } from 'mypackage';

The error is:

W20180126-11:07:08.933(1)? (STDERR) Error: Cannot find module 'mypackage'
W20180126-11:07:08.933(1)? (STDERR)     at Function.Module._resolveFilename (module.js:536:15)
W20180126-11:07:08.933(1)? (STDERR)     at Function.resolve (internal/module.js:18:19)
W20180126-11:07:08.933(1)? (STDERR)     at Object.require (/private/var/folders/q_/nyqwc8q55qx3c_153hvt8zy00000gn/T/meteor-test-runqigr0c.jhjdg/.meteor/local/build/programs/server/boot.js:287:32)
W20180126-11:07:08.934(1)? (STDERR)     at makeInstallerOptions.fallback (packages/modules-runtime.js:651:18)
W20180126-11:07:08.934(1)? (STDERR)     at require (packages/modules-runtime.js:244:16)
W20180126-11:07:08.934(1)? (STDERR)     at collections.tests.js (imports/startup/both/collections.tests.js:1:306)
W20180126-11:07:08.935(1)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:343:9)
W20180126-11:07:08.935(1)? (STDERR)     at require (packages/modules-runtime.js:238:16)
W20180126-11:07:08.935(1)? (STDERR)     at /private/var/folders/q_/nyqwc8q55qx3c_153hvt8zy00000gn/T/meteor-test-runqigr0c.jhjdg/.meteor/local/build/programs/server/app/app.js:7933:1
W20180126-11:07:08.935(1)? (STDERR)     at infos.forEach.info (/private/var/folders/q_/nyqwc8q55qx3c_153hvt8zy00000gn/T/meteor-test-runqigr0c.jhjdg/.meteor/local/build/programs/server/boot.js:414:13)

I tried to resolve this using absolute paths but it did not help. Has somebody experience with this issue?

Upvotes: 1

Views: 592

Answers (2)

Minh Nguyen
Minh Nguyen

Reputation: 490

I recently worked with mui-rte npm package, I needed to make some changes so forked it and try to install locally. Here are steps to make it works.

  1. Go to mui-rte local folder, run npm run build

  2. Inside mui-rte folder, run npm link

  3. Go to the project folder, run npm link mui-rte

It works. Thanks @Mikkel for the link. @Jankapunkt I'm using Meteor too.

Upvotes: 0

Mikkel
Mikkel

Reputation: 7777

There is a special npm feature for doing this called npm link

It allows you to use your local package in preference over the published version. You will first need to an npm link inside the source of the package itself (to make it available)

And then within your project you do it again, but naming the package, eg npm link my-package

More information here:

https://docs.npmjs.com/cli/link

Upvotes: 2

Related Questions