Webpack is using this, which should explicitly ignore the test folder.
{
test: /\.ts$/,
use: [{
loader: 'ts-loader'
//loader: 'awesome-typescript-loader'
}]
,
exclude: '/**/*.test.ts'
}
but it tried to compile my tests (which results in a failing as tests run in node and the webpack build doesn't expect assert to be available in a browser build )
ERROR in /Users/nikos/WebstormProjects/solar-popup/src/tests/SolarPopup.test.ts
(2,20): error TS2307: Cannot find module 'assert'.
The browser webpack build targets es2015:
{
"compilerOptions": {
"target": "es2015",
"declaration": true
},
"exclude": [
"node_modules",
"demo"
]
}
I also tried:
exclude: glob.sync('src/**/*.test.ts')
and
exclude:new RegExp('.test.ts')
but it still tried to compile the test file
Put the excludes in the ts config instead.
@QuantumInformation if you're using a test runner, how do you run tests if the test files are in tsconfig.json exclude? I think in most cases you'll want your .test.ts files to run with a test runner, but not be bundled with webpack.
Wow, I also have the same issue, I need to exclude a /scaffold/ folder and it's not behaving correctly. Is this about to be fixed or is there an alternative to ts-loader that supports excluding folders? It doesn't work either in webpack-config.js or tsconfig.json :(
This is what I ended up doing:
tsconfig.webpack.json
{
"extends": "./tsconfig",
"compilerOptions": {
"sourceMap": true
},
"exclude": [
"**/*.test.ts",
"node_modules"
]
}
Then for my loader I do "ts-loader?configFileName=tsconfig.webpack.json"
Thanks @lukescott , I actually managed to solve it by placing the relative folder path (./app/scaffold) instead of just a folder name in tsconfig.json, but I like your solution as well, I'll try it later. Thanks! :)
I'm using awesome typescript loader now, which seems to do all I need.
Hi there, I'm running into this same issue. One of the npm libs I use has the ts files alongside the js files.
I can compile my TS normally with tsc and no issue.
// tsconfig.json
{
"compilerOptions": {
"plugins": [
{
"name": "tslint-language-service"
}
],
"module": "amd",
"noImplicitAny": true,
"outDir": "./src",
"removeComments": false,
"sourceMap": true,
"jsx": "react",
"jsxFactory": "tsx",
"lib": ["dom", "es2015.promise", "es5", "es6"],
"target": "es5",
"moduleResolution": "node",
"isolatedModules": false,
"experimentalDecorators": true,
"noEmitHelpers": false,
"declaration": false,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true,
"allowJs": true
},
"types": [
"arcgis-js-api",
"chai",
"intern"
],
"include": [
"./src/**/*"
],
"exclude": [
"node_modules"
]
}
But with Webpack 3.5.5 and ts-loader 2.3.3 it keeps trying to compile the ts/tsx files in the node_modules folder.
I tried using the suggestion above to extend my tsconfig and loading it via ts-loader?configFileName=tsconfig.webpack.json
// tsconfig.webpack.tsconfig.json
{
"extends": "./tsconfig",
"exclude": ["./node_modules/**/*.tsx", "node_modules/**/*.ts", "node_modules"]
}
But same issue.
My folder structure is pretty basic.
node_modules/
src/
main.ts
tsconfig.json
tsconfig.webpack.json
webpack.config.js
Any clues what the issue could be? I'm at a bit of a loss on this one.
Thanks!
Thanks for the details - that's really helpful. I'm afraid I don't have any spare time to look at this at present. If you (or anyone else) does I'd be happy to assist. Help is always appreciated!
Sorry, I feel dumb. Another plugin I was using had me add context: __dirname to the webpack config and that is what break the exclude in the loader. Once I removed that context, it works fine. I have a workaround for the other plugin.
Sorry to bother you! Thanks for the awesome work!
Great - thanks for sharing the resolution. This will help others!
I was running into this problem and in my case the issue was my workspace is a monorepo and the project experiencing problems had it's tsconfig named tsconfig.app.json and it was located in a subfolder. I had neglected to add the configFile option inside the project's webpack config file and so the tsconfig file webpack was loading was the base tsconfig.json file located in the workspace root (rather than the tsconfig.app.json file I wanted it to load).
The workaround with separate tsconfig.webpack.json works for me. ts-loader has different name already: 'ts-loader?configFile=tsconfig.webpack.json'
Most helpful comment
This is what I ended up doing:
tsconfig.webpack.json
Then for my loader I do
"ts-loader?configFileName=tsconfig.webpack.json"