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

webpack-cli init creates invalid path for entry unless you specify leading ./ or an abs. path #162

Closed
nilliams opened this issue May 29, 2017 · 13 comments

Comments

@nilliams
Copy link
Contributor

nilliams commented May 29, 2017

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
webpack-cli init

Answer index.js to the question 'Which module will be the first to enter the application?'.

Then if you run webpack, fails with error:

ERROR in Entry module not found: Error: Can't resolve 'index.js' in '/Users/.../test-webpack' 

What is the expected behavior?

  1. Should create a webpack config in which the entry name has been transformed similar to the way output.path is handled, e.g.
// instead of
module.exports = {
  entry: 'index.js',
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  }, ...

// should be
module.exports = {
  entry: path.resolve(__dirname, 'index.js'),
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  }, ...
  1. Ideally the question Yeoman asks should be more explicit about the input format it expects too, so I know to type index.js rather than index.

  2. It should possibly also have a default of index.js? That might also help clarify the format too.

Please mention other relevant information such as the browser version, Node.js version, Operating System and programming language.

$ webpack-cli --version
1.3.3
@nilliams nilliams changed the title webpack-cli init creates invalid path for entry unless you specify leading ./ or an abs. path webpack-cli init creates invalid path for entry unless you specify leading ./ or an abs. path May 29, 2017
@evenstensberg
Copy link
Member

I'll leave this for the community to decide. Letting users supply path themselves is the most secure, as we dunno where either folder/location is.

@nilliams
Copy link
Contributor Author

Okay I can see that, however, it seems to be a problem regardless that if I type index.js I end up with an invalid config?

What is the user expected to do here, enter ./index.js instead? Or edit the generated config manually?

@ghost
Copy link

ghost commented May 29, 2017

@nilliams I think it's better for you to specify the entry with a relative/absolute path.

https://webpack.js.org/configuration/entry-context:

The entry object is where webpack looks to start building the bundle. The context is an absolute string to the directory that contains the entry files.

So basically entry is a file(s) path, not a module name or anything else.

@nilliams
Copy link
Contributor Author

Thanks, wasn't aware of context, though the generated config isn't using it. Perhaps it should be because:

By default the current directory is used, but it's recommended to pass a value in your configuration. This makes your configuration independent from CWD (current working directory).

Currently entering the leading ./ is the only way you can end up with a working config.

Sidenote on that: Typing a leading ./ does not seem the kind of thing you typically do at a prompt that is designed to make an init easy, (and probably would not be intuitive for Windows users).

At a minimum, can I suggest the prompt question be changed to clarify this, it is currently:

Which module will be the first to enter the application?

Perhaps:

Which module path will be the first to enter the application [example: ./index.js]?

Optionally that example could be the default instead. (I personally would vote for this, for speed of starting new projects, especially if it then offered to create it for me if it didn't exist).

Alternative solutions:

  1. If you enter index.js, it will correctly handle it for you, in a forgiving way and normalize that into ./index.js or path.resolve(__dirname, 'index.js') if we don't want to specify context.

  2. If you enter index.js, it will 'error' and re-prompt you to enter a relative path.

@evenstensberg
Copy link
Member

Actually you just have to type ./index. Context is not ideal, as it's better to default to pwd. An example, would be good though. [example: './index'].

Let's just stick with adding an example.

@nilliams
Copy link
Contributor Author

Sounds good to me, thanks!

@avivr
Copy link
Contributor

avivr commented Jun 25, 2017

I'd like to give it a try

@evenstensberg
Copy link
Member

Sweet! Ping me if you need help @avivr !

avivr pushed a commit to avivr/webpack-cli that referenced this issue Jun 25, 2017
DanielaValero added a commit that referenced this issue Jul 3, 2017
feat: add examples for single and multiple entries prompt (#162)
@DanielaValero
Copy link
Contributor

Hello guys, now that the example has been merged, I guess that we can close this issue? @ev1stensberg @nilliams

@nilliams
Copy link
Contributor Author

nilliams commented Jul 4, 2017

Hmm, doesn't seem right? Single entry LGTM, but the examples for multiple entries seem incorrect.

'Type the name you want for your modules (entry files), separated by comma [example: 'app']'

Example should be multiple names, comma-separated, e.g. [example: 'app,admin']

Then for the location question they suggest dist rather than src (./) dir, and have the .js extension which ends up duplicated in the webpack.config output).

What is the location of '${entryProp}'? [example: '../dist/app.js']`

Believe this should be: [example: './app'] or [example: './${entryProp}']

I also noticed that if you choose vendor as an entry name, you end up with the following error, is this something you're aware of or should I open an issue for it?

ERROR in CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (vendor)

@evenstensberg
Copy link
Member

Looks fine to me. Vendor as a entry name is commonly used, this may be an error with your code. Comment your config and let's see :)

@nilliams
Copy link
Contributor Author

nilliams commented Jul 4, 2017

Sorry if my comment was not clear, but please can you reopen, as this is not resolved. The examples for multiple entry will create a broken config?

(I'll create another issue for the ERROR in CommonsChunkPlugin thing. It is similar to this problem I believe, and it is broken regardless of name, sorry for red-herring on 'vendor').

@evenstensberg
Copy link
Member

@nilliams the entry prompts are just an example, you're free to choose whatever name you want. If you think this should be changed, send a PR, happy to help! (Also, it won't create a broken config )

If you're running init and creating a bundle in the dist folder that may be the case of your error. If you want to send in a PR with a fix, that would be 💯

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

No branches or pull requests

4 participants