Ts-loader: Cannot resolve export class Instance

Created on 10 May 2016  路  9Comments  路  Source: TypeStrong/ts-loader

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'

Most helpful comment

Something like

resolveLoader: {
           root: [
                path.join(__dirname, "node_modules")
           ],
           fallback: path.join(__dirname, "node_modules")
},

All 9 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

piernik picture piernik  路  7Comments

kimthangatm picture kimthangatm  路  3Comments

konpikwastaken picture konpikwastaken  路  4Comments

rafiek picture rafiek  路  6Comments

LinusU picture LinusU  路  5Comments