pcb icon indicating copy to clipboard operation
pcb copied to clipboard

Plugin's runtime wasn't added to one of your bundle entries.

Open bkniffler opened this issue 6 years ago • 14 comments

Hey, I'm getting this error

ERROR in OfflinePlugin: Plugin's runtime wasn't added to one of your bundle entries. See this https://goo.gl/YwewYp for details.

I've gone through older issues and made sure that all loaders have the -loader part in webpack.config. I'm also not using the dev server for production. The entry is a single index.js that includes:

  const offline = require('offline-plugin/runtime');
  offline.install({
    onUpdating: () => {
      console.log('SW Event:', 'onUpdating');
    },
    onUpdateReady: () => {
      console.log('SW Event:', 'onUpdateReady');
      offline.applyUpdate();
    },
    onUpdated: () => {
      console.log('SW Event:', 'onUpdated');
      // window.location.reload(); // Only needed with autoUpdates
    },
    onUpdateFailed: () => {
      console.log('SW Event:', 'onUpdateFailed');
    },
  });

Also, the browser console will complain about offline-plugin: runtime was installed without OfflinePlugin being added to the webpack.config.js. See https://goo.gl/2Ca7NO for details..

Is there anything else I could check? Already tried updating webpack to 3.5.1, to no avail.

bkniffler avatar Aug 09 '17 09:08 bkniffler

Hi @bkniffler can you share your webpack config please?

GGAlanSmithee avatar Aug 09 '17 09:08 GGAlanSmithee

Yes, the core webpack stuff https://github.com/bkniffler/olymp/blob/master/packages/core/webpack-config.es6

The offline config https://github.com/bkniffler/olymp/blob/master/packages/core/offline.es6

And the babel stuff https://github.com/bkniffler/olymp/blob/master/packages/webpack-babel/index.es6

And the runtime https://github.com/bkniffler/olymp/blob/master/packages/core/web/index.es6

bkniffler avatar Aug 09 '17 14:08 bkniffler

Sounds weird, but unfortunately I don't have time to help you right now. Maybe next week.

NekR avatar Aug 09 '17 23:08 NekR

I'll try and investigate more, also I'll make the config a bit more easy to read.

bkniffler avatar Aug 10 '17 08:08 bkniffler

How is it going? Were you able to fix the issue?

NekR avatar Aug 18 '17 17:08 NekR

I still didn't manage to make it work. Its definitely the last plugin added to my webpack config and I've tried a lot of different stuff without success. I have no clue whats going on.

https://github.com/bkniffler/olymp/blob/master/packages/core/offline.es6 https://github.com/bkniffler/olymp/blob/master/packages/core/web/index.es6

bkniffler avatar Sep 15 '17 01:09 bkniffler

If I set the __tests.ignoreRuntime to true, the sw.js file will be created, though still the client complains about offline-plugin: runtime was installed without OfflinePlugin being added to the webpack.config.js. See https://goo.gl/2Ca7NO for details.

bkniffler avatar Sep 15 '17 05:09 bkniffler

Got it! The paths are a problem, like for example

var resource = _path3['default'].resolve(compiler.context, result.resource);

if (resource !== runtimePath) {
   return callback(null, result);
}
/* this works =>
if (resource.indexOf('node_modules/offline-plugin/runtime.js') !== -1) {
   return callback(null, result);
}
*/

My webpack config is inside a symlinked package, thus the resource path will never match the runtime path currently.

My current workaround is to require offline-plugin by

const OfflinePlugin = require(path.resolve(process.cwd(), 'node_modules', 'offline-plugin'));

bkniffler avatar Sep 15 '17 06:09 bkniffler

@bkniffler interesting. Can you show me what resource and runtimePath path you have in that situation? Also I'm glad you were able to solve it :-)

NekR avatar Sep 15 '17 14:09 NekR

resource = /Users/me/app/node_modules/offline-plugin/runtime.js

runtimePath = /Users/me/framework/packages/core/node_modules/offline-plugin/runtime.js

I got a framework project which is a lerna repo and it holds everything that can be reused between projects (webpack config, react SSR stuff, apollo client, etc). I'm symlinking it to my app so I extend the framework whenever I require and immediately see how it affects my app. This works great for everything (and I really use a lot of plugins), except for the offline plugin. Not sure if its worth to change the plugins behavior, I think it really is an edge case. But then again, maybe tweaking the plugin to only check for the node_modules/offline-plugin/xxx part of a path might be simple enough.

bkniffler avatar Sep 15 '17 22:09 bkniffler

I had the same issue with a symlinked project using lerna. @bkniffler fix worked for me as well.

nvanselow avatar Sep 17 '17 19:09 nvanselow

I'm going to label this is a bug and maybe solve some day. Thanks for additional info @bkniffler and great the workaround worked for both, you and @nvanselow.

NekR avatar Apr 29 '18 23:04 NekR

For me this issue was solved by adding

new webpack.EnvironmentPlugin(
  NODE_ENV: 'production'
}),

inside the list of plugins (plugins:) in the file webpack.prod.babel.js.

rikhuijzer avatar Aug 15 '19 12:08 rikhuijzer

If I set the __tests.ignoreRuntime to true, the sw.js file will be created, though still the client complains about offline-plugin: runtime was installed without OfflinePlugin being added to the webpack.config.js. See https://goo.gl/2Ca7NO for details.

This applies to me, and even trying the provided solutions don't work.

I have resolve symlinks turned on because of a similar situation with lerna, packageA has the webpack configs, offline-plugin dependency and webpack dependency while packageB has the webapp code and a dependency on packageA.

To enable local development, the package.json in packageB has:

"dependencies": {
    "packageA": "link:../../packageA",

This project is based on React-boilerplate so the webpack implementation is just like https://github.com/react-boilerplate/react-boilerplate/blob/master/internals/webpack/webpack.prod.babel.js#L89 and the runtime usage is like https://github.com/react-boilerplate/react-boilerplate/blob/master/app/app.js#L94

I just have no clue where to go from here....

outdooricon avatar Aug 17 '19 11:08 outdooricon