"In package.js, Npm.require can only find built-in modules."


#1

Hi!

I’ve ran into an issue that i suspect is due to my lack of understanding of how meteor and npm works, so any help is appreciated!

Due to reasons i had to add a package manually in my project, as a local (?) package, and i need an npm.require in package.js order for it to work. But i get the error message

“can’t find npm module ‘simpl-schema’. In package.js, Npm.require can only find built-in modules.”

But the docs simply states “Require a package that was specified using Npm.depends().” for Npm.require.

I’ve used the “meteor npm install --save” on both the local package and the top-level, and ‘simpl-schema’ is found in both places under node_modules. I use the lines

Npm.depends({
‘simpl-schema’: ‘1.4.2’,
});

Npm.require(“simpl-schema”);

in the package.js.

Any ideas? Should it work or am i way off?

Thx in advance!


#2

Use Npm.depends in the package.js and Npm.require in the code where you actually need the module


#3

I find that when using npm packages from within a Meteor package, it is almost always best to use tmeasday:check-npm-versions and specify in the README that the package will need to be installed manually from npm. Using Npm.depends causes your meteor package to have it’s own separate copy of the package which not only makes your app heavier, but can also lead to version mismatch.

I generally put this in a separate file and then import it at the top level of my client or server code

version-check.js

import { checkNpmVersions } from 'meteor/tmeasday:check-npm-versions';

checkNpmVersions({
    ‘simpl-schema’: ‘1.4.2’,
}, 'your-package-name');

client/server code

import '../version-check.js';

//package code.

#4

Thx for your input! Using the tmeasday:check-npm-versions is indeed a good idea.