类型错误:无法调用未定义的方法“charCodeAt" [英] TypeError: Cannot call method 'charCodeAt' of undefined
问题描述
我用 webpack 创建了一个裸项目,只有一个加载器,ts-loader.由于以下错误,Webpack 失败:
I created a bare project with webpack with only one loader, ts-loader. Webpack is failing due to the following error:
ERROR in ./app.ts
Module build failed: TypeError: Cannot call method 'charCodeAt' of undefined
at getRootLength (/home/ravioli/IdeaProjects/dummyWebpack/node_modules/ts-loader/node_modules/typescript/bin/typescript.js:997:18)
at Object.isRootedDiskPath (/home/ravioli/IdeaProjects/dummyWebpack/node_modules/ts-loader/node_modules/typescript/bin/typescript.js:1051:16)
at rootReferencePath (/home/ravioli/IdeaProjects/dummyWebpack/node_modules/ts-loader/index.js:72:23)
at /home/ravioli/IdeaProjects/dummyWebpack/node_modules/ts-loader/index.js:87:93
at Array.map (native)
at ensureDependencies (/home/ravioli/IdeaProjects/dummyWebpack/node_modules/ts-loader/index.js:87:35)
at Object.loader (/home/ravioli/IdeaProjects/dummyWebpack/node_modules/ts-loader/index.js:103:5)
在原生 Javascript 文件上测试时,Webpack 按预期运行.错误发生在使用 Typescript 文件和 ts-loader 时,错误的来源是(正如您在堆栈中看到的).
When tested on vanilla Javascript files Webpack runs as expected. The error occurs when working with Typescript files and the ts-loader, where the origin of the error is (as you can see in the stack).
删除以下行后问题解决:///
(文件的内容不影响错误 - 我已经检查过).
Problem solves once removing the following line:
///<reference path="testi.d.ts" />
(The content of the file does not affect the error - I've checked).
这是示例项目的链接,从 src_ts 文件夹运行 webpack
:https://github.com/ravitb/dummyWebpack
Here is a link to the example project, run webpack
from the src_ts folder:
https://github.com/ravitb/dummyWebpack
我在这里错过了什么?!
What am I missing here?!
推荐答案
这是一个问题,其中 ts-loader 引入了 TypeScript 1.5,该问题具有重大更改,而不是坚持使用 TypeScript 1.4.我已经推出了一个新版本(0.3.4)来解决这个问题.抱歉出现问题.
This was an issue where ts-loader was pulling in TypeScript 1.5 which had breaking changes instead of sticking with TypeScript 1.4. I've pushed out a new version (0.3.4) that should take care of this. Sorry for the problem.
这篇关于类型错误:无法调用未定义的方法“charCodeAt"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!