Is it possible to transpile local modules from node_module?

心不动则不痛 提交于 2019-12-04 13:05:49

Well, I faced this error since I am using es2015 to compile the parent module. If you use commonjs, you wont face this issue.

You can transpile the node module code by adding below in webpack configurations in karma.config.file.

webpack: {
            resolve: {
                extensions: ['', '.ts', '.js']
            },

            module: {
                loaders: [
                    {
                        // This will transpile Typescript files
                        test: /\.ts(x?)$/,
                        exclude: /node_modules/,
                        loader: "babel-loader" + "?presets[]=es2015" + "!ts-loader",
                    },
                    {
                        // This will transpile ES2015 javascript files
                        test: /\.js(x?)$/,
                        include: [
                            path.resolve(__dirname, "node_modules/<<YOUR MODULE NAME>>")
                        ],
                        loader: "babel-loader" + "?presets[]=es2015"
                    }
                ]
            }
        },

Now, Webpack will transpile both JS/TS code using babel-loader.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!