ts-loader icon indicating copy to clipboard operation
ts-loader copied to clipboard

Unable to get ts-loader to compile files in node_modules.

Open trusktr opened this issue 6 years ago • 5 comments

My Webpack config has this:

        {
          test: /\.tsx?$/,
          include: [/src\//, /node_modules\/@scope\/some-package/],
          loader: 'ts-loader',
          options: {
            transpileOnly: true,
            allowTsInNodeModules: true,
            configFile: '../../tsconfig.json',
          },
        },

and the configFile at the root of my project has:

  "include": ["src/**/*", "node_modules/@scope/some-package/src/util/**/*"]

And then my source does

import {SomeThing} from '@scope/some-package/src/util/SomeThing'

Expected Behaviour

It should work

Actual Behaviour

Webpack says something like

    ERROR in ../node_modules/@scope/some-package/src/tiles/SomeThing.worker.ts 46:7
    Module parse failed: Unexpected token (46:7)
    You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
    |   // because xmldom tries to access "window.DOMParser". See webpack.config (here
    |   // or in other utils).
    > ;(self as any).DOMParser = require('xmldom').DOMParser
    | 
    | const textDecoder = new TextDecoder()

The as any is TypeScript that ts-loader isn't handling.

Did I miss something in the configuration?

Steps to Reproduce the Problem

I have a private repo. Willing to sign an NDA (if I can get one)?

Location of a Minimal Repository that Demonstrates the Issue.

^^^

trusktr avatar Dec 13 '19 02:12 trusktr

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 11 '20 03:02 stale[bot]

Closing as stale. Please reopen if you'd like to work on this further.

stale[bot] avatar Feb 18 '20 03:02 stale[bot]

Having exactly same situation. So desperately want to find a solution T_T

Related: https://github.com/TypeStrong/ts-loader/issues/278

klesun avatar Apr 27 '21 22:04 klesun

mee too, I'm getting the same

hoangtuan438 avatar Feb 22 '22 08:02 hoangtuan438

https://www.npmjs.com/package/ts-loader#allowtsinnodemodules ?

alextoul avatar Jan 26 '23 15:01 alextoul