node.js - 类型错误 : Cannot read property 'substr' of undefined - source-node. js

标签 node.js ionic-framework ionic2

此错误是解决 this question 的结果

这是我的 ionic 信息:

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 是否依赖源映射来运行?由于错误的产生是因为没有构建

最佳答案

此错误来自于一个 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] || '';

这个解决方案的问题是你不能把它放到版本控制中,因为这是 Node 模块

关于node.js - 类型错误 : Cannot read property 'substr' of undefined - source-node. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41907409/

相关文章:

mysql - Node.js ES6 类私有(private)存储

Javascript JSON.parse 与外来字符的问题

javascript - 如何在 Node 中的 process.exit 之后启动另一个进程

ionic-framework - 如何在没有质量降低和目标宽度和高度的情况下在 Ionic 3 中调整图像大小?

javascript - Angular 翻译未知 $translateProviderProvider

javascript - 未捕获( promise ): TypeError: Cannot read property 'apply' of undefined in ionic 2 app

java - 哪个平台作为服务/基础设施作为服务器提供商为其免费层提供最多的后端资源?

button - 我会使用 Ionic Framework 在导航栏中插入两个按钮

angular - 如何在 Ionic 2 中设置带有选项卡的侧面菜单?

javascript - 来自变量的 Ionic3 背景图像