Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'length' of undefined #1023

Closed
wind4gis opened this issue Aug 14, 2019 · 18 comments
Closed

TypeError: Cannot read property 'length' of undefined #1023

wind4gis opened this issue Aug 14, 2019 · 18 comments
Labels

Comments

@wind4gis
Copy link

Describe the bug

A 馃挴 way to do this is to provide your configuration via a GitHub gist and/or to use markdown when describing which commands you used when the error occurred! Be precise and clear in your description of the bug.

What is the current behavior?
when I run webpack --mode development(or production), the webpack-cli shows TypeError: Cannot read property 'length' of undefined on the line node_modules\webpack-cli\bin\cli.js:93. my computer is win10

This is where you elaborate on the current behavior of the cli, how it behaves normally differing from the previous version/build you did.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

1.just create a folder on win10
2.npm i -S webpack@next
3.npm i -S webpack-cli@latest
4.write "dev": "webpack --mode development" in package.json
5.npm run dev

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Please paste the results of webpack-cli info here, and mention other relevant information
image

Additional context
Add any other context about the problem here like linking to an similar issue you might think is the cause.

@evenstensberg
Copy link
Member

Hi, thanks for submitting an issue. It's a bug, I've done a patch here:

#1024

Which hopefully will land as a patch soon

@wind4gis
Copy link
Author

@evenstensberg It seems that there is still this bug

@evenstensberg
Copy link
Member

Could you try out the #1024 branch and check if it fixes the bug?

@ryanspice
Copy link

I ran into this issue and pulled your branch it seems to be working now.

@ryanspice
Copy link

@evenstensberg not sure if this is to be expected but an empty webpack config object
image brings up the same error.

@ryanspice
Copy link

actually it might be something else, not quite sure, but trying to plug in my existing config I have seen this error pop up.

@ryanspice
Copy link

yeah im not sure why but when i tried to run it with a config now it was always giving me this error

image

it looks like webpackConfigurationValidationErrors is returning undefined??

it runs if i modify a file

image

@evenstensberg
Copy link
Member

yes, options might be null / undefined, so the error is from validating the schema. Do you think you can figure out when the options obj is nil @ryanspice ?

@evenstensberg evenstensberg reopened this Aug 18, 2019
@ryanspice
Copy link

@evenstensberg yeah it seems like validateschemea.js on webpack@5.0.0-alpha.20 doesnt have a return

image

@evenstensberg
Copy link
Member

@sokra can we have that?

@ryanspice
Copy link

I created a bug report: webpack/webpack#9591

I was gonna create a branch and make a PR but then I realised I dont think i can do that there.

@sokra
Copy link
Member

sokra commented Aug 19, 2019

The validateSchema API changed a bit, since we are using schema-util now. It throws a ValidationError when validation failed. Also note that the name of the validation error changed from WebpackOptionsValidationError to ValidationError.

@evenstensberg
Copy link
Member

Do you have a proposed way of using the schema with the new api? Not getting a message from validating the schema as of:

const validateSchema = require("webpack").validateSchema;
const ValidationError = require("webpack").validate;

const webpackConfigurationValidationErrors = validateSchema(webpackConfigurationSchema, options);
if (webpackConfigurationValidationErrors.length) {
       const error = ValidationError(webpackConfigurationValidationErrors);
        console.error(error.message);
	process.exit(-1);
}

@sokra
Copy link
Member

sokra commented Aug 19, 2019

try {
  validateSchema(webpackConfigurationSchema, options);
} catch(error) {
  console.error(error.message);
  process.exit(-1);
}

@sokra
Copy link
Member

sokra commented Aug 19, 2019

If you want to support both version maybe like this:

let error;
try {
  const errors = validateSchema(webpackConfigurationSchema, options);
  if(errors && errors.length > 0) {
    const WebpackOptionsValidationError = require("webpack").WebpackOptionsValidationError;
    error = new WebpackOptionsValidationError(errors);
  }
} catch(err) {
  error = err;
}

if(error) {
  console.error(error.message);
  process.exit(-1);
}

@ryanspice
Copy link

I'm not quite sure I understand why returning the value isn't appropriate.. It returns an empty array with no errors, would it not have an array populated with errors if there were some?
I probably just don't understand a fundamental part like how it would set the value if its not returning anything in the first place.

@ryanspice
Copy link

@sokra @evenstensberg no? lol

@willgriffiths
Copy link

Fixed by #1065. Landed in v3.3.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants