错误:找不到 npm 模块“时刻”
Posted
技术标签:
【中文标题】错误:找不到 npm 模块“时刻”【英文标题】:Error: Can't find npm module 'moment' 【发布时间】:2017-01-17 16:41:55 【问题描述】:我有一个在本地主机上完美运行的 Meteor 应用程序,但是当我将它部署到远程 heroku
服务器时,我收到以下错误。
(我正在实施this)
有什么办法可以解决这个问题吗?
2016-09-09T13:26:02.533532+00:00 heroku[web.1]: Starting process with command `.meteor/heroku_build/bin/node .meteor/heroku_build/app/main.js`
2016-09-09T13:26:06.806440+00:00 heroku[web.1]: Process exited with status 1
2016-09-09T13:26:06.813921+00:00 heroku[web.1]: State changed from starting to crashed
2016-09-09T13:26:06.704013+00:00 app[web.1]: /app/.meteor/heroku_build/app/programs/server/node_modules/fibers/future.js:280
2016-09-09T13:26:06.704027+00:00 app[web.1]: throw(ex);
2016-09-09T13:26:06.704028+00:00 app[web.1]: ^
2016-09-09T13:26:06.704029+00:00 app[web.1]:
2016-09-09T13:26:06.704030+00:00 app[web.1]: Error: Can't find npm module 'moment'. Did you forget to call 'Npm.depends' in package.js within the 'modules-runtime' package?
2016-09-09T13:26:06.704031+00:00 app[web.1]: at Object.Npm.require (/app/.meteor/heroku_build/app/programs/server/boot.js:198:17)
2016-09-09T13:26:06.704032+00:00 app[web.1]: at options.fallback (packages/modules-runtime/modules-runtime.js:21:1)
2016-09-09T13:26:06.704032+00:00 app[web.1]: at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:88:1)
2016-09-09T13:26:06.704033+00:00 app[web.1]: at meteorInstall.server.main.js (server/main.ts:1:19)
2016-09-09T13:26:06.704035+00:00 app[web.1]: at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1)
2016-09-09T13:26:06.704035+00:00 app[web.1]: at server/main.ts:65:4
2016-09-09T13:26:06.704036+00:00 app[web.1]: at /app/.meteor/heroku_build/app/programs/server/boot.js:292:10
2016-09-09T13:26:06.704036+00:00 app[web.1]: at Array.forEach (native)
如果我heroku run bash
登录heroku。在/app/typings/globals
我看到以下内容:
es6-collections es6-promise google-maps google.maps meteor moment
这似乎与 Windows localhost 上的内容相匹配:
时刻也存在于node_modules
这里是my node_modules\moment\package.js
:
var profile =
resourceTags:
ignore: function(filename, mid)
// only include moment/moment
return mid != "moment/moment";
,
amd: function(filename, mid)
return /\.js$/.test(filename);
;
我的package.json
:
"dependencies":
"@angular/common": "^2.0.0-rc.4",
"@angular/compiler": "^2.0.0-rc.4",
"@angular/core": "^2.0.0-rc.4",
"@angular/forms": "^0.2.0",
"@angular/http": "^2.0.0-rc.4",
"@angular/platform-browser": "^2.0.0-rc.4",
"@angular/platform-browser-dynamic": "^2.0.0-rc.4",
"@ionic/cloud-angular": "^0.4.0",
"angular2-meteor": "^0.6.2",
"angular2-moment": "^0.8.2",
"es6-shim": "^0.35.0",
"ionic-angular": "^2.0.0-beta.11",
"ionic-native": "1.3.2",
"ionicons": "3.0.0",
"meteor-client-side": "^1.3.4",
"moment": "^2.14.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"socket.io": "^1.4.8",
"zone.js": "^0.6.12"
,
部署时从日志中获取sn-p:
remote: -----> Building Meteor app with ROOT_URL: https://git.heroku.com/remote-thewhozoo.git
remote: server/collections.ts (1, 21): Cannot find module 'meteor/mongo'.
remote: server/collections.ts (2, 29): Cannot find module 'api/models'.
remote: server/methods.ts (1, 22): Cannot find module 'meteor/meteor'.
remote: server/methods.ts (2, 28): Cannot find module 'meteor/check'.
remote: server/main.ts (1, 25): Cannot find module 'moment'.
remote: server/main.ts (2, 22): Cannot find module 'meteor/meteor'.
remote:
remote: Unable to resolve some modules:
remote:
remote: "moment" in /tmp/build_29ec6195d953bd56c0670f7d9ee489a4/server/main.js
remote: (os.linux.x86_64)
remote:
remote: If you notice problems related to these missing modules, consider running:
remote:
remote: meteor npm install --save moment
remote:
remote: -----> Moving built slug to /tmp/build_29ec6195d953bd56c0670f7d9ee489a4/.meteor/heroku_build/app
remote: -----> Installing npm production dependencies on built slug
remote:
remote: > fibers@1.0.13 install /tmp/build_29ec6195d953bd56c0670f7d9ee489a4/.meteor/heroku_build/app/programs/server/node_modules/fibers
remote: > node build.js || nodejs build.js
remote:
remote: `linux-x64-v8-4.5` exists; testing
remote: Binary is fine; exiting
remote:
remote: > meteor-dev-bundle@0.0.0 install /tmp/build_29ec6195d953bd56c0670f7d9ee489a4/.meteor/heroku_build/app/programs/server
remote: > node npm-rebuild.js
remote:
remote:
remote: "meteor-dev-bundle": "0.0.0",
remote: "npm": "3.10.6",
remote: "ares": "1.10.1-DEV",
remote: "http_parser": "2.7.0",
remote: "icu": "56.1",
remote: "modules": "46",
remote: "node": "4.5.0",
remote: "openssl": "1.0.2h",
remote: "uv": "1.9.1",
remote: "v8": "4.5.103.37",
remote: "zlib": "1.2.8"
remote:
index.d.ts
declare module 'moment'
var moment: moment.MomentStatic;
export = moment;
我确实在流星项目的根目录中有符号链接:
更新
我已经找到了我认为的问题,但我还不能 100% 确定如何解决它。
问题是符号链接指向本地存在的目录,但不在远程服务器上。
更新
我删除了所有符号链接,然后将文件放在那里,然后部署,当服务器尝试启动时,我仍然收到相同的错误:
2016-09-11T15:23:06.155551+00:00 heroku[web.1]: State changed from crashed to starting
2016-09-11T15:23:09.146909+00:00 heroku[web.1]: Starting process with command `.meteor/heroku_build/bin/node .meteor/heroku_build/app/main.js`
2016-09-11T15:23:13.712742+00:00 heroku[web.1]: State changed from starting to crashed
2016-09-11T15:23:13.640003+00:00 app[web.1]: /app/.meteor/heroku_build/app/programs/server/node_modules/fibers/future.js:280
2016-09-11T15:23:13.640048+00:00 app[web.1]: throw(ex);
2016-09-11T15:23:13.640073+00:00 app[web.1]: ^
2016-09-11T15:23:13.640075+00:00 app[web.1]: Error: Can't find npm module 'moment'. Did you forget to call 'Npm.depends' in package.js within the 'modules-runtime' package?
2016-09-11T15:23:13.640076+00:00 app[web.1]: at Object.Npm.require (/app/.meteor/heroku_build/app/programs/server/boot.js:198:17)
2016-09-11T15:23:13.640077+00:00 app[web.1]: at options.fallback (packages/modules-runtime/modules-runtime.js:21:1)
2016-09-11T15:23:13.640078+00:00 app[web.1]: at meteorInstall.server.main.js (server/main.ts:1:19)
2016-09-11T15:23:13.640079+00:00 app[web.1]: at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1)
2016-09-11T15:23:13.640079+00:00 app[web.1]: at server/main.ts:65:4
2016-09-11T15:23:13.723869+00:00 heroku[web.1]: Process exited with status 1
有什么想法吗?
我已经跑了:meteor npm install --save
我在boot.js
找到了这个,但我不确定作者在做什么。
try
return require(name);
catch (e)
// Try to guess the package name so we can print a nice
// error message
// fileInfo.path is a standard path, use files.pathSep
var filePathParts = fileInfo.path.split(files.pathSep);
var packageName = filePathParts[1].replace(/\.js$/, '');
// XXX better message
throw new Error(
"Can't find npm module '" + name +
"'. Did you forget to call 'Npm.depends' in package.js " +
"within the '" + packageName + "' package?");
更新
我删除了node_modules/
的.gitignore
,现在我没有收到任何错误。
但是,我是 Meteor 的新手,所以不知道如何测试它。但是当我尝试使用 http://remote-thewhozoo.herokuapp.com/
或 https://remote-thewhozoo.herokuapp.com/
调用应用程序时,我收到 404 错误:
2016-09-11T16:20:15.183895+00:00 heroku[router]: at=info method=GET path="/sockjs/info?cb=jwgw2yuvgl" host=remote-thewhozoo.herokuapp.com request_id=a49fafb2-9708-46d2-8117-2c789bfa6a3e fwd="105.186.215.147" dyno=web.1 connect=1ms service=2ms status=404 bytes=132
我确实检查了 Mongo 数据库,它有我的应用程序创建的集合。所以 Meteor 一定是在运行,我只是不知道如何访问它。
有什么想法吗?
【问题讨论】:
我的 localhost 是 Windows 机器,heroku 是 Linux。可能是由于区分大小写问题还是其他原因? 【参考方案1】:您可以在项目根目录中尝试meteor npm install
吗?
如果时刻没有出现在该列表中,您可以试试meteor npm install --save moment
吗?
否则,请您发布您的 package.js - 它应该在 app/programs/server/ 中
【讨论】:
谢谢,我现在正忙着尝试。我只是在做git push
。一个简单的问题,拥有gitignore
的node_modules
是否正确?
没关系,只要记住每次克隆到新机器或更改任何依赖项后拉取时npm install
。
我确实尝试了meteor npm install --save moment
,但是当我尝试执行git add/commit/push
时,它说没有进行任何更改。 Your branch is up-to-date with 'origin/master'
有什么想法吗?【参考方案2】:
确保这一行:"moment": "^2.14.1"
是您的 package.json
然后运行npm install
【讨论】:
我刚刚在上面的问题中添加了package.json
。它确实有"moment": "^2.14.1"
如果问题仍然存在,我会同时执行npm install -g moment
和npm install moment
,后者显然位于您的流星根目录中。
我确实尝试过meteor npm install --save moment
& npm install -g moment
& npm install moment
,但是当我尝试执行git add/commit/push
时,它说没有进行任何更改。 Your branch is up-to-date with 'origin/master'
有什么想法吗?
这应该不是问题。通常不会检测到 node_modules 中的更改,因为它们应该从 package.json
自动安装【参考方案3】:
我认为这是您的 buildpack 的问题。尝试遵循本指南 - https://meteorcoder.wordpress.com/2016/09/24/how-to-deploy-meteor-apps-with-heroku/
【讨论】:
【参考方案4】:我跑了:npm install moment react-moment & 有效。 npm 官方网站有两种不同的安装方式,它们都给了我错误。
【讨论】:
以上是关于错误:找不到 npm 模块“时刻”的主要内容,如果未能解决你的问题,请参考以下文章
npm 错误!找不到模块'spdx-expression-parse'
任何 npm 命令都会返回错误“找不到模块 yallist”,甚至 npm -v
通过 npm 安装的引导程序引发有关“错误:找不到模块 'jQuery'”的错误
npm 错误!找不到模块'./access-error.js'