【问题标题】:TypeError: Cannot read property 'substr' of undefined - source-node.jsTypeError:无法读取未定义的属性“substr”-source-node.js
【发布时间】:2017-06-13 22:16:34
【问题描述】:

由于解析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 是否依赖源映射来运行?由于未构建而出现错误

【问题讨论】:

  • 在另一个问题中注意到你在 package.json 中没有 sw-toolbox .. 似乎 1.0.0 版本的应用脚本依赖于此.. 不确定这是否是确切原因跨度>
  • 这不是确切的问题。这是我在扩展组件时也遇到的 webpack 源映射的错误。也许您使用的是 typescript 2.1.5 而不是 2.0.9?我通过转到 node_modules 中的这个文件并添加一个默认值来修复它,这样它就不会是未定义的。
  • 如果你取消 package.json 中的 source maps 也可以避免这个 bug。很抱歉我没有明确的答案
  • @misha130 你能告诉我你在那里提到的 2 个建议修复中的任何一个吗?我使用的是 2.0.9,所以这不是问题

标签: node.js ionic-framework ionic2


【解决方案1】:

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

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

【讨论】:

  • 嗯,这确实有效。但是,正如您所指出的,这不是最好的解决方案,因为我无法将其推送到 vcs。用离子提出这个问题是否合理?我会接受这个答案,因为它已经解决了问题
  • 我想是的。这可能是 angular 或 webpack 的问题,而不是 ionic 本身。
  • 如果您的默认浏览器是 mozilla,这将不起作用...首先将您的默认浏览器设置为 chrome,然后此工作.. 如果它可以帮助任何人.. 感谢您的回答
【解决方案2】:

我添加了配置:

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

...到似乎修复了错误的 packages.json。

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

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-08-26
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 2020-05-15
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多