ERROR in Can't find self.__WB_MANIFEST in your SW source in TypeScript project
See original GitHub issueLibrary Affected: Current version: 5.1.3
Issue or Feature Request Description:
When trying to build my webpack project, I run into the error
ERROR in Can't find self.__WB_MANIFEST in your SW source.
I’ve tried some searching, but all the related issues don’t point me in the right direction and the docs are no help either.
webpack.config.js
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { InjectManifest } = require('workbox-webpack-plugin');
module.exports = (env = {}) => {
const mode = env.production ? 'production' : 'development';
const apiUrl = env.production
? 'https://xxx.cloudfunctions.net'
: 'http://localhost:5001/xxx/us-central1';
return {
mode,
entry: './src/index.tsx',
output: {
filename: `main${env.production ? '-[contenthash]' : ''}.js`,
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: { 'react-dom': '@hot-loader/react-dom' },
},
module: {
rules: [
{
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ['file-loader'],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
new webpack.DefinePlugin({
mode,
API_URL: JSON.stringify(apiUrl),
}),
new InjectManifest({
swSrc: path.resolve(__dirname, './service-worker.ts'),
}),
],
devServer: {
historyApiFallback: true,
},
};
};
service-worker.ts
// Listen for install event, set callback
self.addEventListener('install', function (event) {
console.log('installed');
});
index.ts
...
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker
.register('/service-worker.js')
.then((registration) => {
console.log('SW registered: ', registration);
})
.catch((registrationError) => {
console.log('SW registration failed: ', registrationError);
});
});
}
...
However, the process seems to work correctly. When I serve my page, I see the installed
console log, and all other project functionality works as well.
Any idea what the root cause of this issue is?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Webpack workbox Can't find self.__WB_MANIFEST in your ...
It was my webpack config for injectManifest bug, I fixed it like this : new WorkboxPlugin.InjectManifest({ swSrc: path.join(process.cwd(), ...
Read more >Building a Service Worker with Workbox 5, TypeScript ...
In this post, I'll concentrate on one of the first building blocks that we've integrated into our Angular application: a service worker. The...
Read more >Ultimate Guide to PWAs with Workbox
This post is a complete guide to building a Progressive Web App (PWA) from the beginning using Google's Workbox. By the end of...
Read more >How to build a progressive web app (PWA) with Node.js
OpenSSL to generate a self-signed certificate (more on that later) ... In the browser, access http://localhost to see the page with just ...
Read more >Add a web app manifest
The web app manifest is a simple JSON file that tells the browser about your web application and how it should behave when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you’d like to use the
InjectManifest
plugin, you need to includeself.__WB_MANIFEST
somewhere in yourswSrc
file. TheInjectManfiest
plugin will look for that symbol and replace it with the manifest created as part of the build process—i.e. literally “injecting the manifest” into yourswSrc
.You’d normally do something in your
swSrc
like the following to make use of the manifest:If you don’t want to use
workbox-precaching
, then you don’t need to use theInjectManifest
plugin at all. You can use any of the other Workbox libraries that you want, and just compile yourservice-worker.ts
as another entry alongside your main entry inwebpack
. TheInjectManifest
plugin is only needed if you want to inject the precache manifest.i set import {precacheAndRoute} from ‘workbox-precaching’;
precacheAndRoute(self.__WB_MANIFEST);
error show : Can’t find self.__WB_MANIFEST in your SW source