我遵循关于使用以下技术堆栈设置web应用程序的这篇很长但内容很丰富的文章:
示例代码可以找到这里。
我一直在跟踪,进展得很好,我确实理解了最重要的概念。但是,当我试图运行它(在我使用git clone下载了它之后)时,我得到了一个错误,如下所示:
$ npm install
$ npm start生成的输出(包括错误)如下:
> react-ssr-example@0.0.1 start /Users/nburk/Developer/node/templates/react-universal-web-apps-simple
> npm-run-all --parallel gulp server
> react-ssr-example@0.0.1 server /Users/nburk/Developer/node/templates/react-universal-web-apps-simple
> node-dev app/babel-server.js
> react-ssr-example@0.0.1 gulp /Users/nburk/Developer/node/templates/react-universal-web-apps-simple
> gulp
[19:10:39] Using gulpfile ~/Developer/node/templates/react-universal-web-apps-simple/gulpfile.js
[19:10:39] Starting 'build:scss'...
[19:10:39] Starting 'build:watch:app'...
TypeError: Cannot read property 'filename' of undefined
at Object.obj.(anonymous function) [as runInThisContext] (/Users/nburk/Developer/node/templates/react-universal-web-apps-simple/node_modules/node-dev/lib/hook.js:25:55)
at Object.<anonymous> (/Users/nburk/Developer/node/templates/react-universal-web-apps-simple/node_modules/graceful-fs/fs.js:10:13)
at Module._compile (module.js:425:26)
at Module._extensions..js (module.js:432:10)
at nodeDevHook (/Users/nburk/Developer/node/templates/react-universal-web-apps-simple/node_modules/node-dev/lib/hook.js:58:7)
at require.extensions.(anonymous function) (/Users/nburk/Developer/node/templates/react-universal-web-apps-simple/node_modules/babel-core/lib/api/register/node.js:214:7)
at Object.nodeDevHook [as .js] (/Users/nburk/Developer/node/templates/react-universal-web-apps-simple/node_modules/node-dev/lib/hook.js:58:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
[19:10:39] Finished 'build:watch:app' after 12 ms
[19:10:39] Starting 'lint:app'...
[ERROR] 19:10:39 TypeError
[19:10:39] Starting 'server'...有人看到我错过了什么吗?我不知道从哪里开始,错误中的文件名并没有告诉我任何事情.
更新
我检查了发生错误的文件(/node_modules/node-dev/lib/hook.js),下面是导致错误的代码:
/**
* Patch the specified method to watch the file at the given argument
* index.
*/
function patch(obj, method, optionsArgIndex) {
var orig = obj[method];
if (!orig) return;
obj[method] = function () {
var opts = arguments[optionsArgIndex];
var file = typeof opts == 'string' ? opts : opts.filename;
if (file) callback(file);
return orig.apply(this, arguments);
};
}发布于 2016-05-16 21:35:48
通过这样做,您可以简单地通过显式强制以前版本的node来解决这个问题:
npm i node-dev@3.0.0 --save-devFix#130 https://github.com/fgnass/node-dev/issues/130带来了@rramakrishnaa中提到的其他一些bug。
发布于 2016-05-16 17:31:35
因为您试图访问值未定义的变量的属性,所以会得到该错误。在您的示例中,opts是从var opts = arguments[optionsArgIndex];获得这一行的值,您不能访问未定义变量的属性。
在访问对象的嵌套属性之前,将其封装在尝试捕获或添加检查中。在JavaScript中,直接访问嵌套变量通常被认为是一种糟糕的方法。
例如,您应该使用var a = b.c.d;而不是var a = (a && a.b && a.b.c) || <some default value>;
在第一种情况下,如果b或c未定义,则应用程序将崩溃,但是,如果b或c在第二种情况下未定义,则将为a分配所提供的默认值。
https://stackoverflow.com/questions/37259608
复制相似问题