I think one can reproduce this using Immutable js:
npm install immutable --save
The typescript definitions work immediately in VSCode because it has typescript defined in the package.json but ts-loader using webpack gives me error in webpack:
error TS2307: Cannot find module 'immutable'.
I found a workaround, by explicitely listing immutable.d.ts in the files section of webpack specific tsconfig:
tsconfig.webpack.json
{
"compilerOptions": {
"target": "es6",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"jsx": "react"
},
"exclude": [
"typings/main.d.ts",
"typings/main"
],
"files": [
"node_modules/immutable/dist/immutable.d.ts"
]
}
Another odd thing is if I remove "files" from there completly it will seek all d.ts files from all node_modules directories and gives a bunch of duplicate errors.
So it must be "files" : [] for ts-loader to work at all.
@Ciantic Actually, that's the wrong way to use it. It might be an accident that it's working for you in VSCode. The field in package.json should be typings. The field you allude to is non-standard and not used by TypeScript. See https://github.com/Microsoft/TypeScript/wiki/Typings-for-npm-packages.
I'm having the same problem. I'm using a module that has typings definition in its package.json, however ts-loader can't seem to resolve them, and I get:
TS2307: Cannot find module 'ui-router-core'.
I am facing the same issue. ts-loader is loading the typings if the _main_ field points to a js file but if it points to a ts file, it doesnot load the typings folder. I have created a sample project with the recreation steps.
I tried compiling the same using tsc and it compiles properly without any issues.
@elboman Are you using node module resolution or CommonJS?
@bipinpoudyal I don't understand, what do you mean by "the typings folder".
Edit: I see the typings file issue. Hard to pin down what's going on since I'm not familiar with it, but please don't ever do this in production. Publish JavaScript modules with typings, or TypeScript projects - I wouldn't combine them.
By the way, all these three issues are separate - they aren't the same issue. Advice on one of them does not apply to the others.
@blakeembrey This is not a production setup but a development time setup where I want to develop a library which will be consumed by another module. I have a workaround where I can export the same definitions from the _main_ ts file, but since TSC compiles fine with the same setup I thought I will bring it to your notice.
Btw, should I raise a separate issue for this?
@bipinpoudyal Thanks for bringing it up. I'd create a separate issue, just want to note it would likely happen with Webpack anyway since it'd start resolving via package.json main - so even if the cause is patched, I'd guess might still run into issues as it starts compiling node modules. Still, I can try to take a look - feel free to separate out the issue 馃槃
Edit: I don't think you need the typings field if you're using a .ts file in main though. Could be wrong though.
Are we still seeing this issue, or can we close this @Ciantic ?
I'm quiet sure this can be closed.
Most helpful comment
I'm having the same problem. I'm using a module that has
typingsdefinition in itspackage.json, howeverts-loadercan't seem to resolve them, and I get: