Webpack build fail when added spec file next to the component file #1419

Closed
opened 2025-08-09 17:20:04 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @Doomape on 8/26/2016

I have a problem with webpack build when i added a counter.spec.ts file next to the counter component, it says cannot find name 'it' and 'expect'. That's strange because in the ts loader i have added exclude: [/.(spec).ts$/] but this file is still included.

This is my webpack config:

var path = require('path');
var webpack = require('webpack');
var merge = require('extendify')({ isDeep: true, arrays: 'concat' });
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractCSS = new ExtractTextPlugin('styles.css');
var devConfig = require('./webpack.config.dev');
var prodConfig = require('./webpack.config.prod');
var isDevelopment = process.env.ASPNETCORE_ENVIRONMENT === 'Development';

module.exports = merge({
    resolve: {
        extensions: [ '', '.js', '.ts' ]
    },
    debug: true,
    module: {
        loaders: [
            { 
                test: /\.ts$/, 
                include: /ClientApp/, 
                loader: 'ts-loader?silent=true',
                exclude: [/\.(spec)\.ts$/]
            },
            { test: /\.html$/, loader: 'raw-loader' },
            { test: /\.css/, loader: extractCSS.extract(['css']) },
            { test: /\.scss/, loader: ExtractTextPlugin.extract("style", "css?sourceMap!sass?sourceMap") } 
        ]
    },
    entry: {
        main: ['./ClientApp/boot-client.ts']
    },
    output: {
        path: path.join(__dirname, './../../wwwroot', 'dist'),
        filename: '[name].js',
        publicPath: '/dist/'
    },
    plugins: [
        extractCSS,
        new webpack.DllReferencePlugin({
            context: __dirname,
            manifest: require('./../../wwwroot/dist/vendor-manifest.json')
        })
    ]
}, isDevelopment ? devConfig : prodConfig);

I get these errors in the console:

ERROR in /Users/User/Desktop/NetCore/ClientApp/components/counter/counter.spec.ts
(1,1): error TS2304: Cannot find name 'it'.

ERROR in /Users/User/Desktop/NetCore/ClientApp/components/counter/counter.spec.ts
(2,9): error TS2304: Cannot find name 'expect'.

*Originally created by @Doomape on 8/26/2016* I have a problem with webpack build when i added a counter.spec.ts file next to the counter component, it says cannot find name 'it' and 'expect'. That's strange because in the ts loader i have added exclude: [/.(spec).ts$/] but this file is still included. This is my webpack config: ``` var path = require('path'); var webpack = require('webpack'); var merge = require('extendify')({ isDeep: true, arrays: 'concat' }); var ExtractTextPlugin = require('extract-text-webpack-plugin'); var extractCSS = new ExtractTextPlugin('styles.css'); var devConfig = require('./webpack.config.dev'); var prodConfig = require('./webpack.config.prod'); var isDevelopment = process.env.ASPNETCORE_ENVIRONMENT === 'Development'; module.exports = merge({ resolve: { extensions: [ '', '.js', '.ts' ] }, debug: true, module: { loaders: [ { test: /\.ts$/, include: /ClientApp/, loader: 'ts-loader?silent=true', exclude: [/\.(spec)\.ts$/] }, { test: /\.html$/, loader: 'raw-loader' }, { test: /\.css/, loader: extractCSS.extract(['css']) }, { test: /\.scss/, loader: ExtractTextPlugin.extract("style", "css?sourceMap!sass?sourceMap") } ] }, entry: { main: ['./ClientApp/boot-client.ts'] }, output: { path: path.join(__dirname, './../../wwwroot', 'dist'), filename: '[name].js', publicPath: '/dist/' }, plugins: [ extractCSS, new webpack.DllReferencePlugin({ context: __dirname, manifest: require('./../../wwwroot/dist/vendor-manifest.json') }) ] }, isDevelopment ? devConfig : prodConfig); ``` I get these errors in the console: ERROR in /Users/User/Desktop/NetCore/ClientApp/components/counter/counter.spec.ts (1,1): error TS2304: Cannot find name 'it'. ERROR in /Users/User/Desktop/NetCore/ClientApp/components/counter/counter.spec.ts (2,9): error TS2304: Cannot find name 'expect'.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1419
No description provided.