tsconfigFolder/../Test.ts
export default class Test{
}
tsconfigFolder/../Demo.ts
import Test from './Test';
const Demo = new Test();
export default Demo;
tsconfigFolder/test.ts
import Demo from '../Demo'
console.log(Demo)
webpack config entry is test.ts
tsconfig at tsconfigFolder
webpack.config.js at tsconfgFolder
It will show error
ERROR in ../Demo.ts
Module not found: Error: Cannot resolve module 'ts-loader'
@twoeo do you have ts-loader installed?
Yes!
There is no problem if Demo.ts and Test.ts in tsconfigFolder.
There is no problem if definition of class Test is in Demo.ts
Problem only appear when test.ts import Demo.ts, and Demo.ts import Test.ts, and Demo.ts&Test.ts is at the parent folder of tsconfigFolder
@twoeo and where is your node_modules folder is located relatively to tsconfigFolder?
Yes, tsconfigFolder/node_modules,
and webpack & typescript link global.
Could be reproduced by this 3 simple files.
tsc -p . works well
I think that problem is that webpack resolves all loaders relatively to required files. Please try to add resolveLoader section to your webpack.config.json https://webpack.github.io/docs/configuration.html#resolveloader
Something like
resolveLoader: {
root: [
path.join(__dirname, "node_modules")
],
fallback: path.join(__dirname, "node_modules")
},
Cool !!
resolveLoader solved this !
I think that problem is that webpack resolves all loaders relatively to required files.
That's right. It works if I "npm install ts-loader" at ../tsconfigFolder
Thank you so much !
Most helpful comment
Something like