arunoda / meteor-up-legacy

Production Quality Meteor Deployments
MIT License
2.26k stars 395 forks source link

mupx deploy failing with Npm.require #854

Open netpoe opened 8 years ago

netpoe commented 8 years ago

I have been deploying my meteor app on a Mac flawlessly until I added a node_module and call the Npm.require method.

This works fine in localhost:3000 but not with mupx deploy:

Here's the log:

mupx logs --tail=50

Meteor Up: Production Quality Meteor Deployments
------------------------------------------------
Configuration file : mup.json
Settings file      : settings.json

[104.236.109.222] Error: Cannot find module 'mandrill-api/mandrill'
[104.236.109.222]     at Function.Module._resolveFilename (module.js:338:15)
[104.236.109.222]     at Function.Module._load (module.js:280:25)
[104.236.109.222]     at Module.require (module.js:364:17)
[104.236.109.222]     at require (module.js:380:17)
[104.236.109.222]     at Object.Npm.require (/bundle/bundle/programs/server/boot.js:150:18)
[104.236.109.222]     at server/methods/methods-emails.js:1:20
[104.236.109.222]     at /bundle/bundle/programs/server/app/server/methods/methods-emails.js:48:4
[104.236.109.222]     at /bundle/bundle/programs/server/boot.js:242:10
[104.236.109.222]     at Array.forEach (native)
[104.236.109.222]     at Function._.each._.forEach (/bundle/bundle/programs/server/node_modules/underscore/underscore.js:79:11)
[104.236.109.222] npm WARN deprecated This version of npm lacks support for important features,
[104.236.109.222] npm WARN deprecated such as scoped packages, offered by the primary npm
[104.236.109.222] npm WARN deprecated registry. Consider upgrading to at least npm@2, if not the
[104.236.109.222] npm WARN deprecated latest stable version. To upgrade to npm@2, run:
[104.236.109.222] npm WARN deprecated
[104.236.109.222] npm WARN deprecated   npm -g install npm@latest-2
[104.236.109.222] npm WARN deprecated
[104.236.109.222] npm WARN deprecated To upgrade to the latest stable version, run:
[104.236.109.222] npm WARN deprecated
[104.236.109.222] npm WARN deprecated   npm -g install npm@latest
[104.236.109.222] npm WARN deprecated
[104.236.109.222] npm WARN deprecated (Depending on how Node.js was installed on your system, you
[104.236.109.222] npm WARN deprecated may need to prefix the preceding commands with `sudo`, or if
[104.236.109.222] npm WARN deprecated on Windows, run them from an Administrator prompt.)
[104.236.109.222] npm WARN deprecated
[104.236.109.222] npm WARN deprecated If you're running the version of npm bundled with
[104.236.109.222] npm WARN deprecated Node.js 0.10 LTS, be aware that the next version of 0.10 LTS
[104.236.109.222] npm WARN deprecated will be bundled with a version of npm@2, which has some small
[104.236.109.222] npm WARN deprecated backwards-incompatible changes made to `npm run-script` and
[104.236.109.222] npm WARN deprecated semver behavior.
[104.236.109.222] npm WARN package.json meteor-dev-bundle@0.0.0 No description
[104.236.109.222] npm WARN package.json meteor-dev-bundle@0.0.0 No repository field.
[104.236.109.222] npm WARN package.json meteor-dev-bundle@0.0.0 No README data
[104.236.109.222] => Starting meteor app on port:80
[104.236.109.222]
[104.236.109.222] /bundle/bundle/programs/server/node_modules/fibers/future.js:245
[104.236.109.222]                       throw(ex);
[104.236.109.222]                             ^
[104.236.109.222] Error: Cannot find module 'mandrill-api/mandrill'
[104.236.109.222]     at Function.Module._resolveFilename (module.js:338:15)
[104.236.109.222]     at Function.Module._load (module.js:280:25)
[104.236.109.222]     at Module.require (module.js:364:17)
[104.236.109.222]     at require (module.js:380:17)
[104.236.109.222]     at Object.Npm.require (/bundle/bundle/programs/server/boot.js:150:18)
[104.236.109.222]     at server/methods/methods-emails.js:1:20
[104.236.109.222]     at /bundle/bundle/programs/server/app/server/methods/methods-emails.js:48:4
[104.236.109.222]     at /bundle/bundle/programs/server/boot.js:242:10
[104.236.109.222]     at Array.forEach (native)
[104.236.109.222]     at Function._.each._.forEach (/bundle/bundle/programs/server/node_modules/underscore/underscore.js:79:11)

Here's my package.json

{
  "name": "developerfullstack.com",
  "version": "1.0.0",
  "description": "Emprendedores que programan",
  "dependencies": {
    "mandrill-api": "^1.0.45"
  },
  "devDependencies": {
    "mandrill-api": "^1.0.45"
  },
  "scripts": {
    "test": "test"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/netpoe/DevFS.git"
  },
  "keywords": [
    "MOOC",
    "Education"
  ],
  "author": "netpoe",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/netpoe/DevFS/issues"
  },
  "homepage": "https://github.com/netpoe/DevFS#readme"
}

Here's the code where Npm.require() is called (also tried with meteorhacks:npm Meteor.npmRequire():

let mandrill = Npm.require('mandrill-api/mandrill');

I also tried, before posting this issue:

#614

@arunoda asked for the reproducible app as well, here's the repo.

Server info

DigitalOcean UBUNTU droplet

MasterJames commented 8 years ago

It says something in the output about updating depreciated npm via

npm -g install npm@latest-2

Anyway if you update everything incluing meteor 1.2 you might need to change the nodes version in the settings file to 0.10.40 The fibers error I recall happens in that case.

netpoe commented 8 years ago

Thanks @MasterJames, a few questions:

netpoe commented 8 years ago

Think I found how to specify the nodeVersion in the mup.json file:

// WARNING: nodeVersion defaults to 0.10.36 if omitted. Do not use v, just the version number.
"nodeVersion": "0.10.40",

Am I right?

MasterJames commented 8 years ago

Maybe reinstall npm all together. Once you have npm updated or installed freshly on your local deployment box where you run mupx. The -g flag is global and so where you install irrelavent. Otherwise you do it in the project folder same as where you run mupx I suppose. Try both separately (Uninstall other) to see if that makes a difference. Run "meteor update" to update meteor and all included packages. The last line of the settings file in the configuration shown in the Readme of the mupx repo (similar in both versions).

 "deployCheckWaitTime": 120

It's in seconds extending it will again just confirm that's not the problem. Lower it later when it's working and/or if it doesn't make a difference.

MasterJames commented 8 years ago

Yes sorry wrong value you found the right one.

netpoe commented 8 years ago

No success, tried:

Verifying deployment: FAILED

    -----------------------------------STDERR-----------------------------------
    ehavior.
    npm WARN package.json meteor-dev-bundle@0.0.0 No description
    npm WARN package.json meteor-dev-bundle@0.0.0 No repository field.
    npm WARN package.json meteor-dev-bundle@0.0.0 No README data
    => Starting meteor app on port:80

    /bundle/bundle/programs/server/node_modules/fibers/future.js:245
                            throw(ex);
                                  ^
    Error: Cannot find module 'mandrill-api/mandrill'
        at Function.Module._resolveFilename (module.js:338:15)
        at Function.Module._load (module.js:280:25)
        at Module.require (module.js:364:17)
        at require (module.js:380:17)
        at Object.Npm.require (/bundle/bundle/programs/server/boot.js:150:18)
        at server/methods/methods-emails.js:1:20
        at /bundle/bundle/programs/server/app/server/methods/methods-emails.js:48:4
        at /bundle/bundle/programs/server/boot.js:242:10
        at Array.forEach (native)
        at Function._.each._.forEach (/bundle/bundle/programs/server/node_modules/underscore/underscore.js:79:11)

    => Redeploying previous version of the app

    -----------------------------------STDOUT-----------------------------------

    To see more logs type 'mup logs --tail=50'

The main problem is with this file: /bundle/bundle/programs/server/app/server/methods/methods-emails.js requesting the 'mandrill-api/mandrill' module like this:

let mandrill = Npm.require('mandrill-api/mandrill');

I read in other issues that they installed the module manually on the server? If not, maybe something with where is the Npm.require() trying to search for the node_modules directory?

I checked on the server for the /opt/appName/current/bundle/programs/server/package.json file and I think that's the package.json that's specifying the modules on use. Maybe mupx deploy is not adding it to the bundle correctly?

MasterJames commented 8 years ago

So you added it as well as later calling Npm.require right? I'm no expert at this problem but it is reminiscent of some earlier issue? Anyway I'm here to help isolate what's happening. Being remote makes it hard and slow going. Trial and error is the process to isolation. I did a simple Google maybe this will help? http://stackoverflow.com/questions/9023672/nodejs-how-to-resolve-cannot-find-module-error The other example I thought about as I recall the package was not able to be built on the target without what I'm not sure. I'll dig more while you check that link.