rails / webpacker

Use Webpack to manage app-like JavaScript modules in Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unmet peer dependencies

DaniG2k opened this issue Β· comments

Hello,

Every time I run yarn install on my Rails project I'm seeing warning messages like:

warning " > @rails/webpacker@3.0.2" has unmet peer dependency "coffeescript@>= 1.12.7 || >= 2.x".
warning "@rails/webpacker > coffee-loader@0.8.0" has unmet peer dependency "coffeescript@>= 1.8.x".
warning "@rails/webpacker > postcss-cssnext@3.0.2" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning " > vue-loader@13.5.0" has unmet peer dependency "css-loader@*".
warning " > webpack-dev-server@2.9.7" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".

My packages.json file looks like this:

{
  "license": "UNLICENSED",
  "dependencies": {
    "@rails/webpacker": "^3.0.1",
    "vue": "^2.4.3",
    "vue-loader": "^13.0.4",
    "vue-resource": "^1.3.4",
    "vue-template-compiler": "^2.4.3",
    "vue2-dropzone": "^3.0.0",
    "vuelidate": "^0.6.1"
  },
  "devDependencies": {
    "webpack-dev-server": "^2.8.1"
  },
  "version": "1.3.2"
}

I am using node 8.9.2:

β†’ which node
/Users/me/.nvm/versions/node/v8.9.2/bin/node

Am I doing something incorrectly?

Thanks!

Did you try yarn upgrade and see if it works fine? Also, I am not sure how recommended it is, but try getting rid of yarn.lock file (which helps lock your packages and dependencies) and see if it helps.

Please upgrade to latest version of webpacker: yarn upgrade @rails/webpacker.

@gauravtiwari Sorry to add to this closed ticket. I'm encountering similar unmet peer dependencies even after having upgraded to latest version of webpacker 3.1.1 (using yarn upgrade @rails/webpacker). Then I tried a fresh install and came across the same unmet peer dependencies warnings.

Repro steps:

  1. rails new demo
  2. add webpacker 3.1.1 to Gemfile, and bundle
  3. rake webpacker:install
    Warning messages:
warning "@rails/webpacker > postcss-cssnext@3.0.2" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
warning " > webpack-dev-server@2.9.7" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".

resulting package.json:

{
  "dependencies": {
    "@rails/webpacker": "^3.1.1",
    "coffeescript": "1.12.7"
  },
  "devDependencies": {
    "webpack-dev-server": "^2.9.7"
  }
}

I use yarn version 1.3.2.

@serixscorpio No problem :)

Those warnings are harmless (apart from generating noise) but if you are concerned you can use versions of webpack-dev-server per warnings since it's a peer dependency.

Please upgrade to latest version of webpacker: yarn upgrade @rails/webpacker.

So, bundle exec rails webpacker:install installs an old version? Should we add yarn upgrade to the instructions in the readme? Or should we fix webpacker:install?

Those warnings are harmless (apart from generating noise) but if you are concerned you can use versions of webpack-dev-server per warnings since it's a peer dependency.

I am very new to fancy modern style of JS and webpack in general. I do not understand how to follow those instructions to "use versions of webpack-dev-server per warnings." Can you add an example for those who find themselves here? Thanks!

I am not sure if this is an issue with the latest RC (version 4).

This is still an issue with RC 4. Webpacker doesn't seem to add webpack to the package.json, it only adds it to the yarn.lock. I get tons of warning of unmet peer dependencies for webpack. I'm no js expert, but I believe webpack should be added to the dev dependencies of the package.json. A simple yarn add webpack --dev makes these warnings go away.

Adding webpack to devDependencies will prevent you from building/deploying to a production environment (devDependencies are removed when env == production ).  

Have you tried resolving the unmet peer dependencies? Does yarn add webpack successfully add webpack to package.json?

@jakeNiemiec yarn add webpack does make the warnings go away, and adds it to package.json

@jakeNiemiec While adding webpack to the package.json via yarn add webpack works and gets rid of the warnings, it no longer works properly inside of Rails. The server fails to start and complains about missing modules. Removing webpack from the package.json and restarting the server makes everything work like normal again.

Did you try: bundle exec rails webpacker:install or yarn upgrade? It sounds like the module was added to your package.json but the install step was not run.

Just did a fresh install and I am still having this issue:
gem 'webpacker', '>= 4.0.x'
yarn add @rails/webpacker@next
bundle
bundle exec rails webpacker:install
yarn upgrade

yarn upgrade didn't fix anything for me.

yarn install v1.12.3
[1/6] πŸ” Validating package.json...
[2/6] πŸ” Resolving packages...
[3/6] πŸ” Auditing packages...
[4/6] 🚚 Fetching packages...
[5/6] πŸ”— Linking dependencies...
warning "@rails/webpacker > pnp-webpack-plugin > ts-pnp@1.0.0" has unmet peer dependency "typescript@*".
warning " > webpack-dev-server@3.1.14" has unmet peer dependency "webpack@^4.0.0".
warning "webpack-dev-server > webpack-dev-middleware@3.4.0" has unmet peer dependency "webpack@^4.0.0".

Those warnings are about peer dependecies, so it not a problem.

The error webpack-dev-server has unmet peer dependency "webpack@^4.0.0". means "If you are using webpack in your project, make sure its version ^4.0.0 or else webpack-dev-server can break!"

To get rid of the warning, just add the lib/version specified in the warning on your package.json:

"dependencies": {
  ...
  "webpack": "^4.0.0",
  ...
},

@DNA Ensure that you put webpack in dependencies instead of devDependencies see: #1078 (comment)

@jakeNiemiec You are right, I wrote the wrong section in the example, I've fixed it :)

I'm upgrading to webpacker 4 and due to the unmet peer deps license_finder is failing and thus breaking my CI pipelines.. all is lost! πŸ™Œ

/Users/jgallaso/.rvm/gems/ruby-2.3.6/gems/license_finder-5.5.2/lib/license_finder/package_managers/npm.rb:38:in `npm_json': Command 'npm list --json --long --production' failed to execute: npm ERR! peer dep missing: typescript@*, required by ts-pnp@1.0.1 (RuntimeError)

@josemigallas make sure you have a version that includes this line: https://github.com/arcanis/ts-pnp/blob/master/package.json#L24

The only other thing I can think of is what I warned @.DNA about above: try putting all of your packages in dependencies instead of devDependencies

@josemigallas make sure you have a version that includes this line: https://github.com/arcanis/ts-pnp/blob/master/package.json#L24

Do I need to install ts-pnp or typescript for webpacker not to break?

The only other thing I can think of is what I warned @.DNA about above: try putting all of your packages in dependencies instead of devDependencies

Did not help πŸ˜•

Do I need to install ts-pnp or typescript for webpacker not to break?

If they are added to your project properly, you should be able to see them in package.json under dependencies . Also, ensure that they get installed within node_modules on the CI server.

Earlier several people said things like "Those warnings are about peer dependecies, so it not a problem." Looking up "peer dependencies" in Webpack, it looks like it's supposed to mean if you have the thing it has to meet a certain version spec, but you are... not required to have the thing?

But do you have to have the thing after all?

I am not a Webpacker/Webpack expert, I'm still quite confused about what's going on. I feel that the promise of Rails/webpacker integration should be to give me something that, immediately after a by-the-book install, does not give me any warnings or errors. I feel that maybe this isssue should be re-opened.

@jrochkind I am not a Webpacker/Webpack expert, I'm still quite confused about what's going on.

Say you are making oatmeal for breakfast, you have your oats and a liquid ranging from water to (almond/soy/coconut) milk. The oats don't care what kind of liquid they soak up as long as you provide it. In the same way, ts-pnp does not care what kind typescript configuration your project uses as long as you provide it in your dependencies.

To bring this example home, we ask "Why doesn't ts-pnp just solely use typescript as it's own dependency? This would be like using pre-made oatmeal, the liquid part is "just there" and you don't have the choice to change it. In the same way, the package author not only wants you to provide/configure the dependency for yourself but also wants to be able to build off of your specific configuration.

πŸ€”...perhaps not the best example. This is what yarn says:

Having a peer dependency means that your package needs a dependency that is the same exact dependency as the person installing your package. This is useful for packages like react that need to have a single copy of react-dom that is also used by the person installing it.

The peerDependencies object guarantees that, for each entry, any package that requires you will be requested to provide a copy of the dependency listed here, ideally matching the version you requested. It also guarantees that you’ll be able to access this dependency through require(), and finally it also guarantees that the return of require() will be exactly the same version & instance than the one your parent would obtain if they were to require() it themselves.

As a rails dev, you never need to worry about peerDeps apart from ensuring that they are listed in your project's dependencies.

As a rails dev, you never need to worry about peerDeps apart from ensuring that they are listed in your project's dependencies.

In a Rails 5.2 app that was generated with rails new --webpack (or alternately added with bundle exec rails webpacker:install), are the peerDeps listed in the projects dependencies? I think maybe not based on the error messages reported at the top of this ticket? (Which I've encountered too).

Should they be in your projects dependencies already as generated by Rails? Or if not, should there be some clear instructions somewhere telling you to add them? (If I'm understanding right that you need to "ensure that they are listed in your projects dependencies".)

It seems like Rails is setting you up incorrectly here, if you need to ensure the peerDeps are listed in your project's dependencies, but the Rails template doesn't do that for you, and nothing else tells you to. If I'm understanding right what's going on -- because other comments in this ticket said you didn't need to do anything in response to "has unmet peer dependency" warnings. But I think you are disagreeing and saying you do need to do something, you need to ensure the peer dependency is listed in your project's dependencies. (Via... yarn add I guess?) This is confusing and I feel like Rails is dropping the ball somewhere.

The README currently says:

Optional: To fix "unmet peer dependency" warnings,

   yarn upgrade

But yarn upgrade did not fix the "unmet peer dependency warnings", and this ticket was closed anyway. That section of the README actually links here to this very ticket... if I follow it from the README, I am still left unsure what the official webpacker instructions are here.

Not sure how Rails 6 changes things.

should there be some clear instructions somewhere telling you to add them?

Lots of great examples here: https://github.com/rails/webpacker/tree/master/docs

This is confusing and I feel like Rails is dropping the ball somewhere.

This is the key thing: when you make use of package.json & webpack, you have left Rails-land and enter node.js land. The rules are different and I agree that webpackER does not to a good job conveying that.

But yarn upgrade did not fix the "unmet peer dependency warnings"

I don't think that would work for every instance of that error. I would just do yarn add myMissingPeerDependency@x.x.x as the error indicates.

So: warning " > webpack-dev-server@2.9.7" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
is fixed with:
yarn add webpack@^3.0.0

Not sure how Rails 6 changes things.

Rails 6 uses a different version of webpack (4).

OK, yes. But it seems wrong to me that a fresh untouched rails new --webpack (or just rails new if it's default in Rails 6?) gives you something that, before you've done anything else to it, has "unmet peer dependencies" that you need to take manual actions to resolve.

I'm not sure if you're not understanding me, or you just disagree and think this is appropriate, that it's fine that the fresh out of the box un-touched generated Rails app has unmet peer dependencies that a developer needs to notice and take action to resolve? You can disagree!

(I also think it's a problem that the README links to this issue, which has people saying you can just ignore the "unmet peer dependecies" and don't need to do anything -- and indeed that is what I've been doing in my Rails 5.2 app based on that advice. But if I understand you right you are saying that is bad advice?)

it seems wrong to me that a fresh untouched rails new --webpack gives you something that has "unmet peer dependencies" that you need to take manual actions to resolve.

I agree this would be a good PR candidate. You could add the needed deps somewhere around here:

https://github.com/rails/webpacker/blob/master/lib/install/template.rb#L37-L46

I too had this issue, with this error message as other have experienced:

warning "webpack-dev-server > webpack-dev-middleware@3.6.2" has unmet peer dependency "webpack@^4.0.0".
warning " > webpack-dev-server@3.3.1" has unmet peer dependency "webpack@^4.0.0".

Both yarn upgrade and yarn add webpack didn't work for me :(. However, the following did:

yarn upgrade webpack@^4.0.0

πŸŽ‰ Hope that helps!

My personal experience on Rails 5.2.3 I had a lot of these warnings related to webpack

warning " > @ckeditor/ckeditor5-dev-webpack-plugin@8.0.5" has unmet peer dependency "webpack@^4.0.0".
warning " > babel-loader@8.0.6" has unmet peer dependency "webpack@>=2".
warning " > rails-erb-loader@5.5.2" has unmet peer dependency "webpack@^2.0.0 || >= 3.0.0-rc.0 || ^3.0.0".
warning " > webpack-filter-warnings-plugin@1.2.1" has unmet peer dependency "webpack@^2.0.0 || ^3.0.0 || ^4.0.0".
warning " > webpack-modernizr-loader@5.0.0" has unmet peer dependency "webpack@^4.0.0".
warning " > webpack-dev-server@3.8.2" has unmet peer dependency "webpack@^4.0.0".
warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has unmet peer dependency "webpack@^4.0.0".

I also had the latest version of webpack, 4.34.0

I added this to my package.json and it seemed to get rid of all the warnings:

  "resolutions": {
    "webpack": "4.34.0"
  }

The webpacker gem links to this page where I must waste my days to read this whole thread. - needs a one-liner urgently.

commented

Both yarn upgrade and yarn add webpack didn't work for me :(. However, the following did:

yarn upgrade webpack@^4.0.0

@domchristie I can confirm that only that adds the necessary dependency

"webpack": "^4.0.0"

into the dependencies section of the package.json file.

Thank you!

Is this change going to be made in the template that creates a new rails app? IMO a new app should not have any errors. I also found the recommended solution on this thread, but wasted a lot of time on it. It's a confusing error for someone coming to rails for the first time and webpack especially.

I think we want rails to be able to create the cononical hello world app without errors. IMHO that's good for the platform, otherwise, I think people who come to rails for the first time to try it out may get discouraged.

I don't know much about the rails implementation of webpacker and how it is different from webpack and if there are any incompatibilities. However, if the recommended solution for those who do know these details is adding this dependency package.json for a new rails app, it seems reasonable to keep this issue open until that has been done. Any agreement? Thank You

The webpacker gem links to this page where I must waste my days to read this whole thread. - needs a one-liner urgently.

I don't understand why this comment was marked as spam, it represents the frustration that a new rails 6 user could experience because of the errors discussed here. Let's fix this for Rails 6 please. This issue was created before Rails 6 was released! I'm happy to volunteer to make the fix. Please reopen rails/rails#39870 or create a new issue as needed. Thank You