New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.4.2.5] npm "Cannot find module" errors. #8325

Closed
arthurtse opened this Issue Feb 7, 2017 · 17 comments

Comments

Projects
None yet
10 participants
@arthurtse

arthurtse commented Feb 7, 2017

How to produce the error:

  • A node module mod has require('./localFile').
  • A meteor app requires mod.
  • Throws: Error: Cannot find module './localFile'

A script to produce the error:

mkdir mod-bug-test
cd mod-bug-test

mkdir mod
cd mod
touch b.js
echo "require('./b');" > index.js
cd ..

meteor create app
cd app
meteor npm install
cp -a ../mod node_modules/
echo "require('mod');" > main.js
# meteor  # Running meteor throws: Error: Cannot find module './b'

If I use a symlink instead of cp -a ../mod, requiring './b' doesn't throw; but if mod requires a module mod2 and mod2 requires its own local file, meteor will throw.

OS: Linux Mint 18

@hwillson

This comment has been minimized.

Member

hwillson commented Feb 7, 2017

Hi @arthurtea - you repro isn't quite valid though. You're missing a package.json in your mod directory, and you haven't added a dependency on mod in your app's package.json. If you modify your repro steps so that you're creating a package.json like

{
  "main": "index.js",
  "version": "1.0.0"
}

in mod, then adjusting app's package.json to look like

{
  "name": "app",
  "private": true,
  "scripts": {
    "start": "meteor run"
  },
  "dependencies": {
    "meteor-node-stubs": "~0.2.0",
    "babel-runtime": "6.18.0",
    "mod": "1.0.0"
  }
}

your app will start properly, and you won't get any errors.

@macrozone

This comment has been minimized.

macrozone commented Feb 7, 2017

I got the same error with an own npm (let's call it "foo") module after upgrading to 1.4.2.5

  • A node module "foo" has require('./localFile').
  • A meteor app requires "foo"
  • Throws: Error: Cannot find module './localFile'

i removed node_modules and reinstalled with meteor npm install, but it did not help, so i needed to downgrade to 1.4.2.3 again

@hwillson

This comment has been minimized.

Member

hwillson commented Feb 7, 2017

@macrozone - are you able to put together a small reproduction showing this issue? The original reproduction provided in this issue would have thrown that exact same error with 1.4.2.3 (because of the items I mentioned in #8325 (comment)). Thanks!

@arthurtse

This comment has been minimized.

arthurtse commented Feb 7, 2017

@hwillson Thanks. The problem is resolved after I added the dependencies to package.json . A small inconvenience is that I use a lot of npm ln <package>, which doesn't add the dependency to package.json . Now I need to to run npm i -S <package> after linking to add the line.

@jvallarvisp

This comment has been minimized.

jvallarvisp commented Feb 7, 2017

Cannot find module 'websocket'.
The error came from subscriptions-transport-ws module.
so I need to downgrade to 1.4.2.3.

@aaronjudd

This comment has been minimized.

aaronjudd commented Feb 8, 2017

Also when "@org/privatepackage" syntax is used in an import, even though the package is installed and saved via meteor npm.. which is also reported in #8278, this is METEOR@1.4.2.5 specific. Downgrading to 1.4.2.3 all is ok.

@macrozone

This comment has been minimized.

macrozone commented Feb 8, 2017

@gtokenThinhnguyen

This comment has been minimized.

gtokenThinhnguyen commented Feb 8, 2017

I met the same problem with braintree package.

Error: Cannot find module 'depd'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/bundle/bundle/programs/server/npm/node_modules/braintree/lib/braintree/client_token_gateway.js:15:13.

Seem like it cannot find the dependencies inside the braintree package. Please give me some advises. Thanks.

@abernix

This comment has been minimized.

Member

abernix commented Feb 8, 2017

If you're experiencing this problem, please try to reproduce using Meteor 1.4.2.3 and report back if you still have the same issue. It sounds like a couple different issues might be mentioned in this thread.

@gtokenThinhnguyen Your issue is definitely a problem related to Meteor 1.4.2.5. A commit intended to fix some deployments (2613582) is causing nested NPM dependencies to get incorrectly stripped.

That being said, we've unrecommended Meteor 1.4.2.5 which leaves Meteor 1.4.2.3 as the most-recommended version. Stay tuned for updates!

@abernix abernix added the bug label Feb 8, 2017

@benlavalley

This comment has been minimized.

benlavalley commented Feb 8, 2017

The @google/maps npm package seems to reproduce the error on 1.4.2.5.

  1. meteor create --release 1.4.2.5 modulebugrepro
  2. cd modulebugrepro
  3. meteor npm install babel-runtime @google/maps --save
  4. echo var googleMapsClient = require('@google/maps').createClient({key: 'your API key here'}); >> server/main.js
  5. meteor

yields:
Error: Cannot find module './internal/cli'

  1. meteor update --release 1.4.2.3
  2. meteor

Works fine.

@benjamn benjamn added this to the Release 1.4.2.x milestone Feb 8, 2017

@benjamn

This comment has been minimized.

Member

benjamn commented Feb 8, 2017

We're going to do a 1.4.2.6 follow-up release to fix this.

@benjamn benjamn referenced this issue Feb 8, 2017

Merged

Release 1.4.2.6 #8330

1 of 1 task complete
@abernix

This comment has been minimized.

Member

abernix commented Feb 8, 2017

@benlavalley Thanks for the clear and easy reproduction. I can confirm that 1.4.2.6-rc.0 will fix your problem.

@abernix abernix changed the title from After updating to v1.4.2.5, have npm "Cannot find module" errors. to [1.4.2.5] npm "Cannot find module" errors. Feb 8, 2017

@benjamn

This comment has been minimized.

Member

benjamn commented Feb 8, 2017

This should be fixed if you run meteor update --release 1.4.2.6 in your applications.

@benjamn benjamn closed this Feb 8, 2017

@jvallarvisp

This comment has been minimized.

jvallarvisp commented Feb 8, 2017

Still having an issue with meteor update --release 1.4.2.6

Uncaught Error: Cannot find module 'websocket'
    at require (modules-runtime.js?hash=637cb12…:119)
    at meteorInstall.node_modules.subscriptions-transport-ws.dist.client.js (modules.js?hash=883307d…:120843)
    at fileEvaluate (modules-runtime.js?hash=637cb12…:191)
    at require (modules-runtime.js?hash=637cb12…:116)
    at meteorInstall.node_modules.subscriptions-transport-ws.dist.index.js (modules.js?hash=883307d…:120827)
    at fileEvaluate (modules-runtime.js?hash=637cb12…:191)
    at Module.require (modules-runtime.js?hash=637cb12…:116)
    at Module.Mp.import (modules.js?hash=883307d…:320)
    at meteorInstall.client.main.js (main.js:1)
    at fileEvaluate (modules-runtime.js?hash=637cb12…:191)
require @ modules-runtime.js?hash=637cb12…:119
meteorInstall.node_modules.subscriptions-transport-ws.dist.client.js @ modules.js?hash=883307d…:120843
fileEvaluate @ modules-runtime.js?hash=637cb12…:191
require @ modules-runtime.js?hash=637cb12…:116
meteorInstall.node_modules.subscriptions-transport-ws.dist.index.js @ modules.js?hash=883307d…:120827
fileEvaluate @ modules-runtime.js?hash=637cb12…:191
require @ modules-runtime.js?hash=637cb12…:116
Mp.import @ modules.js?hash=883307d…:320
meteorInstall.client.main.js @ main.js:1
fileEvaluate @ modules-runtime.js?hash=637cb12…:191
require @ modules-runtime.js?hash=637cb12…:116
(anonymous) @ app.js?hash=30286d0…:19997

meteor update --release 1.4.2.3 fix it again.

@benjamn

This comment has been minimized.

Member

benjamn commented Feb 9, 2017

@jvallarvisp Hard to tell from the error if that's really the same problem. If you can provide a reproduction, then we can help you track down the problem.

@jvallarvisp

This comment has been minimized.

jvallarvisp commented Feb 9, 2017

I have to update npm module subscriptions-transport-ws to fix it. It is working now using meteor 1.4.2.6

@micahalcorn

This comment has been minimized.

micahalcorn commented Oct 10, 2017

I'm having a similar issue to @benlavalley's in Meteor 1.5.x.x - but specifically in the shell without first requiring the module in server/main.js:

1.5 Works Fine

meteor create --release 1.5 google_maps_test
cd google_maps_test/
meteor npm install --save @google/maps
meteor
meteor shell
> const googleMapsClient = require("@google/maps").createClient({ key: 'test' });
>

1.5.2.2 Does Not

meteor create --release 1.5.2.2 google_maps_test
cd google_maps_test/
meteor npm install --save @google/maps
meteor
meteor shell
> const googleMapsClient = require("@google/maps").createClient({ key: 'test' });
module.js:327
    throw err;
    ^
Error: Cannot find module '@google/maps'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.require.resolve (internal/module.js:16:19)
    at Object.require (/Users/kgb/Dropbox/Meteor/google_maps_test/.meteor/local/build/programs/server/boot.js:225:32)
    at makeInstallerOptions.fallback (packages/modules-runtime.js:641:18)
    at require (packages/modules-runtime.js:234:16)
    at repl:1:-38
    at packages/shell-server/shell-server.js:422:29
    at /Users/kgb/.meteor/packages/promise/.0.9.0.a4wtlf++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:39

1.5.2.2 Works With Require In File

meteor create --release 1.5.2.2 google_maps_test
cd google_maps_test/
meteor npm install --save @google/maps
echo 'const googleMapsClient = require("@google/maps").createClient({ key: "test" });' >> server/main.js
meteor
meteor shell
> const googleMapsClient = require("@google/maps").createClient({ key: 'test' });
>

Am I supposed to require the package on startup for some reason?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment