TypeError:无法读取undefined - source-node.js的属性'substr'

时间:2017-01-28 07:30:44

标签: node.js ionic-framework ionic2

此错误是由于解析this question

而产生的

这是我的ionic info

Cordova CLI: 6.5.0
Ionic Framework Version: 2.0.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.0.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v7.4.0
Xcode version: Not installed

(我也在使用npm v4.1.1

尝试构建@ionic/app-scripts时,我收到以下错误:

E:\Documents\Year_3\Mobile_Application_Development\mammoth-v2\node_modules\webpack-sources\node_modules\source-map\lib\source-node.js:95
      var code = nextLine.substr(0, mapping.generatedColumn -
                         ^

TypeError: Cannot read property 'substr' of undefined
    at Function.<anonymous> (E:\Documents\Year_3\Mobile_Application_Development\mammoth-v2\node_modules\webpack-sources\node_modules\source-map\lib\source-node.js:95:30)
    at Array.forEach (native)
    at BasicSourceMapConsumer.SourceMapConsumer_eachMapping [as eachMapping] (E:\Documents\Year_3\Mobile_Application_Development\mammoth-v2\node_modules\webpack-sources\node_modules\source-map\lib\source-map-consumer.js:155:14)
    at Function.SourceNode_fromStringWithSourceMap [as fromStringWithSourceMap] (E:\Documents\Year_3\Mobile_Application_Development\mammoth-v2\node_modules\webpack-sources\node_modules\source-map\lib\source-node.js:80:24)
    at SourceMapSource.node (E:\Documents\Year_3\Mobile_Application_Development\mammoth-v2\node_modules\webpack-sources\lib\SourceMapSource.js:42:20)
    at ReplaceSource.node (E:\Documents\Year_3\Mobile_Application_Development\mammoth-v2\node_modules\webpack-sources\lib\ReplaceSource.js:69:29)
    at CachedSource.node (E:\Documents\Year_3\Mobile_Application_Development\mammoth-v2\node_modules\webpack-sources\lib\CachedSource.js:12:23)
    at E:\Documents\Year_3\Mobile_Application_Development\mammoth-v2\node_modules\webpack-sources\lib\ConcatSource.js:40:49
    at Array.map (native)
    at ConcatSource.node (E:\Documents\Year_3\Mobile_Application_Development\mammoth-v2\node_modules\webpack-sources\lib\ConcatSource.js:39:60)

如果需要,当我运行npm run build (构建@ionic/app-scripts时,这是构建日志:

[07:28:45]  ionic-app-scripts 1.0.0 
[07:28:45]  build dev started ...
[07:28:45]  clean started ...
[07:28:45]  clean finished in 4 ms
[07:28:45]  copy started ...
[07:28:45]  transpile started ...
[07:28:49]  transpile finished in 4.44 s
[07:28:49]  webpack started ...
[07:28:49]  copy finished in 4.57 s

            **errors arise here**

修改

我添加了配置:

"config": {
    "ionic_generate_source_map": false
},

...到packages.json这似乎可以解决错误,但我现在面临另一个错误:

  

Error: ENOENT: no such file or directory, open 'main.js.map'

当我尝试ionic serve 时会抛出哪些内容(@ionic/app-scripts的版本现在运行正常)

编辑#2:

ionic是否依赖源地图来运​​行?因为错误是由于非构建而产生的

3 个答案:

答案 0 :(得分:8)

此错误来自一个ts文件中有两个2个类/组件。

解决这个问题的野蛮方法。

转到node_modules \ webpack-sources \ node_modules \ source-map \ lib \ source-map \ source-node.js

然后交换所有2次:

var nextLine = remainingLines[0];

到此

var nextLine = remainingLines[0] || '';

此解决方案的问题在于您无法将其置于版本控制中,因为这是节点模块

答案 1 :(得分:2)

我添加了配置:

"config": {
    "ionic_generate_source_map": false
},

... to packages.json似乎修正了错误。

在上面的编辑中,我现在描述了我遇到的另一个错误

答案 2 :(得分:2)

我解决此问题的方法是添加 package.json 此配置选项:

"config": {
    "ionic_source_map_type": "eval"
}