cbll
cbll

Reputation: 7219

.tsx/typescript throws error "TS2307: Cannot find module 'History' only on Ubuntu?

Facing a weird issue with a React/Typescript setup.

Running webpack -p on OSX/Windows compiles just fine with no errors from the TypeScript/TSX compiler at all.

However, on Ubuntu it will throw a TypeScript specific error, specifically:

ERROR in [at-loader] ./src/scenes/Component.tsx:5:23 TS2307: Cannot find module 'History'.

The specific line which throws an error is:

import {History} from "History";

package.json has both normal and @types package for History:

"@types/history": "4.6.0",

"history": "4.7.2",

And again, I can run webpack -p with the exact same code, same webpack configuration and same version on OSX without it throwing an error. Process is the same! However, on Ubuntu the build will fail with the above error.

Upvotes: 1

Views: 454

Answers (2)

Almenon
Almenon

Reputation: 1476

I ran into a similar TS2307 issue only on Ubuntu. I maintained the npm package that was causing the issue, so I had to find out what was causing it and fix it myself.

Ubuntu has a case-sensitive file system, so if you have a import with the wrong case it can cause an issue. However, I had forceConsistentCasingInFileNames turned on in my Typescript options, and all my imports were using the right case.

After some digging it turned out the issue was in my package.json file - the "main" property was "PythonExecutors.js" but it should have been "pythonExecutors.js" 🤦

Upvotes: 0

cbll
cbll

Reputation: 7219

The sinner was awesome-typescript-loader(at-loader). @3.2.x it threw this error; downgrading to @3.1.3 made it go away. This happened after upgrading packages apparently - but again, only seems to affect Ubuntu.

Upvotes: 0

Related Questions