-
-
Notifications
You must be signed in to change notification settings - Fork 644
Closed
Description
Describe the bug
webpack-cli remove webpack.prod.js # any name other than webpack.config.js will throw errorWhat is the current behavior?
Throwing typeError and stopping the execution of the package.
To Reproduce
Steps to reproduce the behavior:
- Create a webpack config filename name other than
webpack.config.js, something likewebpack.prod.jsor anything else - run
$ webpack-cli remove webpack.prod.js
it will throw this.
√ SUCCESS Found config webpack.config.prod.js
internal/validators.js:125
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type objectExpected behavior
This is happeing because in remove-generator.ts if the config filename is not equal to webpack.config.js then it is assigning the configPath as null and then require(configPath) which is resulting in this error
let configPath = path.resolve(process.cwd(), "webpack.config.js");
const webpackConfigExists = fs.existsSync(configPath);
if (!webpackConfigExists) {
configPath = null;
// end the generator stating webpack config not found or to specify the config
}
this.webpackOptions = require(configPath); // typeError here Fix
One way to fix this can be.
to ask the user for the correct webpack config file name , something like this.
let configPath = path.resolve(process.cwd(), "webpack.config.js");
const webpackConfigExists = fs.existsSync(configPath);
if (!webpackConfigExists) {
configPath = null;
console.log("Couldn't find the webpack.config.js in your current directory ")
this.webpackOptions = null
} else {
this.webpackOptions = require(configPath);
}
prompting(){
if (this.webpackOptions == null) {
let configPath;
this.prompt([Confirm("isOtherConfigFilePresent", "Do you have webpack config file with any other name ? ")])
.then(answer => {
const {
isOtherConfigFilePresent
} = answer;
if (isOtherConfigFilePresent) {
this.prompt([Input("configFileName", "Enter your config file name")])
.then(answer2 => {
const {
configFileName
} = answer2;
configPath = configFileName;
})
}
})
this.webpackOptions = require(configPath);
}
}
or
To simply thow a nice error description from if-statement
if (!webpackConfigExists) {
throw new Error("Please rename your config file with webpack.config.js");
}Not sure about these fix as I think yeoman generator will not work properly if we have
this.promptoutsite of theprompting()method or may be inconstructor
with
Inquirerand usingInquirer.prompt()instead ofyeoman's prompt incontructorcan also work
Please paste the results of webpack-cli info here, and mention other relevant information
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
Binaries:
Yarn: 1.15.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD