babel-engine-plugin
babel-engine-plugin copied to clipboard
Struggling to compile
I am using your plugin in combination with create-react-app-typescript, in order to compile mem in production. When adding babel-engine-plugin
I am left with a very vague webpack compiler error:
Failed to compile.
chunk main [entry] static/js/[name].[chunkhash:8].js Cannot read property 'indexOf' of null
I've been diving into various bits of code, trying out different things, but I am running out of ideas and energy. I'm hoping anyone might recognise this and point me in the right direction.
My setup has been compiling fine without the plugin. I can still do the non-production build, because it doesn't use the Uglify plugin. It's the Uglify plugin that clashes with the syntax of mem
, but I guess that is not something unusual.
Below is my config-overrides file, in case that helps.
const { injectBabelPlugin, getLoader } = require("react-app-rewired");
const path = require("path");
const BabelEnginePlugin = require("babel-engine-plugin");
module.exports = function override(config, env) {
const babelLoader = {
loader: "babel-loader",
options: {
presets: ["react-app"],
},
};
const babelEnginePlugin = new BabelEnginePlugin({
presets: ["env"],
});
const tsLoader = getLoader(
config.module.rules,
rule =>
rule.loader &&
typeof rule.loader === "string" &&
rule.loader.indexOf(`${path.sep}ts-loader${path.sep}`) !== -1
);
if (!tsLoader) {
throw new Error("Unable to find ts-loader in the webpack config base");
}
tsLoader.loader = undefined; // remove loader in favor of use
tsLoader.use = [
babelLoader,
{
loader: "ts-loader",
},
];
config.plugins.unshift(babelEnginePlugin);
// For imports with non-relative path from /src
config.resolve.modules = [path.resolve("src")].concat(config.resolve.modules);
config.resolve.extensions = [".tsx", ".ts", ".json", ".js"];
return config;
};
Having the same problem on production builds but I'm not sure it's related to Uglify. When Uglify is disabled the problem persists. Development builds work fine.
#5 seems to be a fix for this. @SamVerschueren, any chance this gets merged and released? I really like this babel plugin, but the current issue is a blocker because production builds fail.
Reviewed the PR. Two things that need to be fixed first.
Awesome, thanks for looking into it!
Can you give it a go with 0.2.0
, PR #5 is merged now.