Meteor-feature-requests: Allow use of installed NPM packages within `meteor shell` even if they have not been imported in server code

Created on 23 Mar 2018  路  7Comments  路  Source: meteor/meteor-feature-requests

Migrated from: meteor/meteor#6624

Isobuild NPM ProjectShell

Most helpful comment

Last tested with Meteor 1.6.0.1, looks like I'm unable to import an NPM package in shell even if it's being imported in my app code.

> import moment from 'moment';
Error: Cannot find module 'moment'
    at makeMissingError (packages/modules-runtime.js:231:12)
    at require (packages/modules-runtime.js:241:19)
    at repl:2:14
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at runBound (domain.js:314:12)
    at evalCommandPromise.then (packages/shell-server/shell-server.js:246:21)
    at /Users/gaurav/.meteor/packages/promise/.0.10.0.ak8m4i++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40

Require also fails:

> const moment = require('moment');
Error: Cannot find module 'moment'
    at makeMissingError (packages/modules-runtime.js:231:12)
    at require (packages/modules-runtime.js:241:19)
    at repl:1:-48
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at runBound (domain.js:314:12)
    at evalCommandPromise.then (packages/shell-server/shell-server.js:246:21)
    at /Users/gaurav/.meteor/packages/promise/.0.10.0.ak8m4i++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40

_Note: Changed the original issue title to reflect that no NPM package installed in app can be used in meteor shell._

All 7 comments

Last tested with Meteor 1.6.0.1, looks like I'm unable to import an NPM package in shell even if it's being imported in my app code.

> import moment from 'moment';
Error: Cannot find module 'moment'
    at makeMissingError (packages/modules-runtime.js:231:12)
    at require (packages/modules-runtime.js:241:19)
    at repl:2:14
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at runBound (domain.js:314:12)
    at evalCommandPromise.then (packages/shell-server/shell-server.js:246:21)
    at /Users/gaurav/.meteor/packages/promise/.0.10.0.ak8m4i++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40

Require also fails:

> const moment = require('moment');
Error: Cannot find module 'moment'
    at makeMissingError (packages/modules-runtime.js:231:12)
    at require (packages/modules-runtime.js:241:19)
    at repl:1:-48
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at runBound (domain.js:314:12)
    at evalCommandPromise.then (packages/shell-server/shell-server.js:246:21)
    at /Users/gaurav/.meteor/packages/promise/.0.10.0.ak8m4i++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40

_Note: Changed the original issue title to reflect that no NPM package installed in app can be used in meteor shell._

Can you provide a small runnable reproduction that shows this happening? This should be working by default. I've put together a small reproduction that shows this working here: https://github.com/hwillson/fr-282

If this isn't working for you, then something else is interfering (and a reproduction from your side would help track down the issue). Thanks!

@hwillson should we close this issue?

Just tried with latest meteor version (1.8.1) and the issue is still there with a slightly different stacktrace

Steps to reproduce:

meteor create --minimal import-npm-package-in-meteor-shell
cd import-npm-package-in-meteor-shell
meteor npm i
meteor npm i moment --save
meteor run

In meteor shell:

> import moment from 'moment';
Error: Cannot find module 'moment'
    at evalCommandPromise.then (packages/shell-server/shell-server.js:249:21)
    at runBound (domain.js:314:12)
    at bound (domain.js:301:14)
    at defaultEval (repl.js:240:29)
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at repl:2:8
    at Module.moduleLink [as link] (/Users/gaurav/.meteor/packages/modules/.0.13.0.10p0eew++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/reify/lib/runtime/index.js:38:38)
    at Module.require (packages/modules-runtime.js:241:17)
    at makeMissingError (packages/modules-runtime.js:222:12)
> const moment = require('moment');
Error: Cannot find module 'moment'
    at evalCommandPromise.then (packages/shell-server/shell-server.js:249:21)
    at runBound (domain.js:314:12)
    at bound (domain.js:301:14)
    at defaultEval (repl.js:240:29)
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at repl:1:-46
    at require (packages/modules-runtime.js:258:21)
    at Module.require (packages/modules-runtime.js:241:17)
    at makeMissingError (packages/modules-runtime.js:222:12)

@gaurav- You need to import the module somewhere in your server code to be able to import it in the server shell. For example, add import "moment"; to server/main.js in your reproduction.

@klaussner so this is working as intended?

If nothing is going to change with regards to this then I think it's better to close this (and possibly add something to the docs).

It's working as intended but I think this a reasonable feature request and should remain open. (I ran into this problem a few times myself. 馃槃) I agree that we should add a note about the current behavior to the docs (here).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mitar picture mitar  路  65Comments

MKRazz picture MKRazz  路  18Comments

mitar picture mitar  路  34Comments

Saeeed-B picture Saeeed-B  路  24Comments

StorytellerCZ picture StorytellerCZ  路  21Comments