TypeError: Cannot call method 'charCodeAt'

2020-06-12 04:56发布

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)

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).

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?!

1条回答
我欲成王,谁敢阻挡
2楼-- · 2020-06-12 05:46

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.

查看更多
登录 后发表回答