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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Did you mean '--entry index.js'?" #2356

Closed
fregante opened this issue Jan 15, 2021 · 12 comments · Fixed by #2369
Closed

Add "Did you mean '--entry index.js'?" #2356

fregante opened this issue Jan 15, 2021 · 12 comments · Fixed by #2369

Comments

@fregante
Copy link

fregante commented Jan 15, 2021

Is your feature request related to a problem? Please describe.

The simplest usage stopped working in v4 and the error is meaningless

❯ webpack --version
webpack 5.14.0
webpack-cli 4.3.1

❯ webpack index.js
[webpack-cli] Unknown command 'index.js'
[webpack-cli] Run 'webpack --help' to see available commands and options

Describe the solution you'd like

Tell me how to fix it rather than having to Google my way out of cryptic error messages.

  ❯ webpack index.js
  [webpack-cli] Unknown command 'index.js'
+ [webpack-cli] Did you mean '--entry index.js'?
  [webpack-cli] Run 'webpack --help' to see available commands and options

Additional context

People having issues:

@snitin315
Copy link
Member

snitin315 commented Jan 15, 2021

As I mentioned in #2322 (comment) , It was difficult to differentiate between an invalid command and an entry point.
Earlier the logic was very hacky.

@snitin315
Copy link
Member

But I think we can do something like follow -

for
webpack index.js

if (isFileExists('invalid')) { 
 logger.error('Did you mean '--entry index.js'?')
} else { 
  // current behaviour
}

@alexander-akait
Copy link
Member

hm, maybe we can do, I will think about it

@alexander-akait
Copy link
Member

I am WIP on old syntax (will be in the next patch release) -

  • webpack ./entry.js
  • webpack entry=./entry.js

@alexander-akait
Copy link
Member

We return: webpack ./entry.js, webpack entry=./entry.js will be in future, need some improvements

@saivan
Copy link

saivan commented Feb 16, 2021

I had code that depended on webpack entry=./entry.js, is there an alternative way to achieve this now (without having to write a webpack config file)?

@anshumanv
Copy link
Member

Tried it and it seems to work for me, does it not work for you?

image

@saivan
Copy link

saivan commented Feb 16, 2021

Sorry to be clear, i'd want to set a different name like: webpack hello=./hello.js second=./second.js. I have no way to set the name of the package by the looks of things

@saivan
Copy link

saivan commented Feb 17, 2021

Another strange thing, is that providing multiple entry points always sets the name field to main (I don't think I set that anywhere). Is that expected behaviour?

@alexander-akait
Copy link
Member

webpack hello=./hello.js second=./second.js is not supported, you need configuration for it, or we should improve it on webpack side

@saivan
Copy link

saivan commented Feb 17, 2021

Well in the meantime, if anybody runs into this issue, you can try something along the lines of:

class CompilerHooks {
  apply(compiler) {
    // Rewrite the "main" entry point 
    compiler.hooks.entryOption.tap('Entry Rewrite', (context, entry) => {
      // Delete the main entry point and get the entry files
      const entryFiles = entry.main.import
      delete entry.main

      // Add new entry points for each file
      for ( let fileName of entryFiles ) {
        const name = path.parse(fileName).name
        entry[name] = { import: [fileName] }      }
    })
  } 
}

Then in your config:

config = {
   plugins: [new CompilerHooks()]
   ...
}

You can even add in some environment variables if you want to make this more elaborate 😄

@alexander-akait
Copy link
Member

If you need webpack --name=./foo.js --other=./bar.js we can implement this, but we need improve it on webpack side

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

Successfully merging a pull request may close this issue.

5 participants