Skip to content

ts-loader can't find typings for npm TS module when allowJS is true #586

@bsouthga

Description

@bsouthga

Minimal repro repository: https://github.com/bsouthga/ts-loader-types-error-example

First off, thanks for all the great work you guys do on ts-loader, its an important part of our build stack!

Issue:

Versions:

Given a JS entry file:

// `index.js`
import './imported'

And an imported typescript file (importing this library):

// `imported.ts`
import { EventRank } from 'event-rank';
console.log(EventRank);

And a webpack config as follows:

module.exports = {
  entry: './src/entry.js',
  output: {
    filename: 'bundle.js'
  },
  resolve: {
    // Add `.ts` and `.tsx` as a resolvable extension.
    extensions: ['.ts', '.tsx', '.js'] // note if using webpack 1 you'd also need a '' in the array as well
  },
  module: {
    loaders: [ // loaders will work with webpack 1 or 2; but will be renamed "rules" in future
      // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
      { test: /\.tsx?$/, loader: 'ts-loader', options: {
        entryFileIsJs: true
      } }
    ]
  }
}

The project will compile fine under tsc, but webpack returns the following error:

ts-loader: Using [email protected] and ~/projects/ts-loader-error/tsconfig.json
Hash: 836c8ecb865d0c8010fe
Version: webpack 3.3.0
Time: 859ms
    Asset     Size  Chunks             Chunk Names
bundle.js  42.4 kB       0  [emitted]  main
   [1] ./src/entry.js 20 bytes {0} [built]
   [2] ./src/imported.ts 64 bytes {0} [built] [1 error]
    + 3 hidden modules

ERROR in ./src/imported.ts
(1,10): error TS2305: Module '"~/projects/ts-loader-error/node_modules/event-rank/dist/src/index"' hasno exported member 'EventRank'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions