Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: path.replace is not a function in ./typescript/lib/typescript.js #26554

Closed
BiosBoy opened this issue Aug 20, 2018 · 7 comments
Closed
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@BiosBoy
Copy link

BiosBoy commented Aug 20, 2018

Hi, today a had faced with such strange issue. A think this probably of a bug.

Environment:
TypeScript Version: 3.1.0
Webpack Version: 4.15.0
Path Version: 0.12.7

Loaders:
AW-Loader Version: 5.2.0
TS-Loader Version: 4.5.0
(both tested with it, the same scenario):

all package above are installed globally and also locally in project

Code of an Error

ERROR in ./src/main.ts
Module build failed (from /Users/react-apps/node_modules/ts-loader/index.js):
TypeError: path.replace is not a function
    at Object.normalizeSlashes (/Users/react-apps/node_modules/typescript/lib/typescript.js:14080:21)
    at Object.combinePaths (/Users/react-apps/node_modules/typescript/lib/typescript.js:14405:31)
    at getWildcardDirectories (/Users/react-apps/node_modules/typescript/lib/typescript.js:24289:48)
    at matchFileNames (/Users/react-apps/node_modules/typescript/lib/typescript.js:24168:35)
    at getFileNames (/Users/react-apps/node_modules/typescript/lib/typescript.js:23765:26)
    at parseJsonConfigFileContentWorker (/Users/react-apps/node_modules/typescript/lib/typescript.js:23712:18)
    at Object.parseJsonConfigFileContent (/Users/react-apps/node_modules/typescript/lib/typescript.js:23662:16)
    at Object.getConfigParseResult (/Users/react-apps/node_modules/ts-loader/dist/config.js:82:40)
    at successfulTypeScriptInstance (/Users/react-apps/node_modules/ts-loader/dist/instances.js:64:40)
    at Object.getTypeScriptInstance (/Users/react-apps/node_modules/ts-loader/dist/instances.js:51:12)
    at Object.loader (/Users/react-apps/node_modules/ts-loader/dist/index.js:16:41)
 @ multi ./src/main.ts webpack-hot-middleware/client?path=http://192.168.0.102:3000/__webpack_hmr

Expected behavior:
Must compile app without any errors

Actual behavior:
Broke on Webpack 4 final compilation stage

Related Issues:
no one with typescript

@BiosBoy BiosBoy changed the title TypeError: path.replace is not a function IN typescript/lib/typescript.js TypeError: path.replace is not a function in ./typescript/lib/typescript.js Aug 20, 2018
@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Aug 20, 2018
@RyanCavanaugh
Copy link
Member

Might be a ts-loader bug. Do you have a repo we can try out?

@fabioberger
Copy link

fabioberger commented Aug 24, 2018

I'm getting this same error when using TypeDoc v0.12.0 with Typescript v3.0.1.

Stacktrace:

Using TypeScript 3.0.1 from /Users/fabio/projects/0x-monorepo-one/node_modules/typescript/lib
/Users/fabio/projects/0x-monorepo-one/node_modules/typescript/lib/typescript.js:14080
        return path.replace(backslashRegExp, ts.directorySeparator);
                    ^

TypeError: Cannot read property 'replace' of undefined
    at Object.normalizeSlashes (/Users/fabio/projects/0x-monorepo-one/node_modules/typescript/lib/typescript.js:14080:21)
    at getCommonSourceDirectory (/Users/fabio/projects/0x-monorepo-one/node_modules/typescript/lib/typescript.js:82737:68)
    at verifyCompilerOptions (/Users/fabio/projects/0x-monorepo-one/node_modules/typescript/lib/typescript.js:84278:27)
    at Object.createProgram (/Users/fabio/projects/0x-monorepo-one/node_modules/typescript/lib/typescript.js:82703:9)
    at Converter.convert (/Users/fabio/projects/0x-monorepo-one/node_modules/typedoc/dist/lib/converter/converter.js:109:26)
    at CliApplication.Application.convert (/Users/fabio/projects/0x-monorepo-one/node_modules/typedoc/dist/lib/application.js:84:37)
    at CliApplication.bootstrap (/Users/fabio/projects/0x-monorepo-one/node_modules/typedoc/dist/lib/cli.js:62:32)
    at CliApplication.Application [as constructor] (/Users/fabio/projects/0x-monorepo-one/node_modules/typedoc/dist/lib/application.js:44:15)
    at new CliApplication (/Users/fabio/projects/0x-monorepo-one/node_modules/typedoc/dist/lib/cli.js:38:42)
    at Object.<anonymous> (/Users/fabio/projects/0x-monorepo-one/node_modules/typedoc/bin/typedoc:4:1)
error Command failed with exit code 1.

As for a repo, we are trying to move to project references in this PR: 0xProject/0x-monorepo#991. You can clone it, run yarn && yarn build from the root directory, then run yarn test:generate_docs:circleci to reproduce the error.

@simonbuchan
Copy link

The failing line in getCommonSourceDirectory is

https://github.com/Microsoft/TypeScript/blob/73ec5964efc4711478b015c8635f0bc8b7bf13d9/src/compiler/program.ts#L801

when debugging, options.configFilePath is indeed undefined. So it looks like another case of bad use of ! (for convenience and tracking, the referenced issue is #18217)

ts-loader is passing options only slightly edited from parseJsonConfigFileContent(), which is returning configFilePath: undefined if that is called without the undocumented configFileName argument, so it looks like this should never be assumed. Should ts-loader add a workaround fix for now, since it shouldn't hurt?

@Akuukis
Copy link

Akuukis commented Sep 13, 2018

I got similar error by using ForkTsCheckerWebpackPlugin. Interestingly the build itself succeeds (it is based on Babel 7 and @babel/preset-typescript).

$ROOT/node_modules/typescript/lib/typescript.js:14077
        return path.replace(backslashRegExp, ts.directorySeparator);
                    ^

TypeError: Cannot read property 'replace' of undefined
    at Object.normalizeSlashes ($ROOT/node_modules/typescript/lib/typescript.js:14077:21)
    at getCommonSourceDirectory ($ROOT/node_modules/typescript/lib/typescript.js:82777:68)
    at verifyCompilerOptions ($ROOT/node_modules/typescript/lib/typescript.js:84318:27)
    at Object.createProgram ($ROOT/node_modules/typescript/lib/typescript.js:82743:9)
    at Function.IncrementalChecker.createProgram ($ROOT/node_modules/fork-ts-checker-webpack-plugin/lib/IncrementalChecker.js:64:19)
    at IncrementalChecker.loadDefaultProgram ($ROOT/node_modules/fork-ts-checker-webpack-plugin/lib/IncrementalChecker.js:108:35)
    at IncrementalChecker.nextIteration ($ROOT/node_modules/fork-ts-checker-webpack-plugin/lib/IncrementalChecker.js:97:64)
    at run ($ROOT/node_modules/fork-ts-checker-webpack-plugin/lib/service.js:11:13)
    at process.<anonymous> ($ROOT/node_modules/fork-ts-checker-webpack-plugin/lib/service.js:38:5)

Versions:

$ yarn list typescript webpack fork-ts-checker-webpack-plugin
├─ fork-ts-checker-webpack-plugin@0.4.9
├─ path@0.12.7
├─ typescript@3.0.3 (typescript@3.1.0-dev.20180913 has identical behavior)
└─ webpack@4.17.2

P.S. Ping to fork-ts-checker-webpack-plugin mainteiner @johnnyreilly as per request at #815

@RyanCavanaugh
Copy link
Member

This seems to be fixed, or at least not affecting anyone anymore

@Sourav-1204
Copy link

i am getting the same error

PS C:\Users\LENOVO\Desktop\HTML\Registration form\src> node app.js
C:\Users\LENOVO\Desktop\HTML\Registration form\node_modules\path-to-regexp\index.js:68
path = path.replace(
^

TypeError: path.replace is not a function
at pathToRegexp (C:\Users\LENOVO\Desktop\HTML\Registration form\node_modules\path-to-regexp\index.js:68:15)
at new Layer (C:\Users\LENOVO\Desktop\HTML\Registration form\node_modules\express\lib\router\layer.js:45:17)
at Function.route (C:\Users\LENOVO\Desktop\HTML\Registration form\node_modules\express\lib\router\index.js:505:15)
at app. [as get] (C:\Users\LENOVO\Desktop\HTML\Registration form\node_modules\express\lib\application.js:4n.js:498:30)
at Object. (C:\Users\LENOVO\Desktop\HTML\Registration form\src\app.js:9:5)
at Module._compile (node:internal/modules/cjs/loader:1546:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
at Module.load (node:internal/modules/cjs/loader:1317:32)
at Module._load (node:internal/modules/cjs/loader:1127:12)
at TracingChannel.traceSync (node:diagnostics_channel:315:14)

Node.js v22.6.0

please help me out !!

@RyanCavanaugh
Copy link
Member

@Sourav-1204 that's an error in your code, not TypeScript's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

6 participants