Module not found error after integrating next-pwa
Summary
The next.config.js code below was working fine before adding next-pwa. But after the next-pwa integration, i started getting "Module not found" errors.
#ERROR
error - ./node_modules/jest-worker/build/workers/ChildProcessWorker.js:9:0 Module not found: Can't resolve 'child_process'
Import trace for requested module: ./node_modules/jest-worker/build/WorkerPool.js ./node_modules/jest-worker/build/index.js ./node_modules/terser-webpack-plugin/dist/index.js ./node_modules/next-pwa/build-custom-worker.js ./node_modules/next-pwa/index.js ./next.config.js ./store/WorkoutStore.js ./context/MyStudio/MyStudioContext.js ./context/Provider.js ./pages/_app.js
https://nextjs.org/docs/messages/module-not-found
#NEXT.CONFIG.JS
const withPWA = require("next-pwa")({
dest: "public",
});
module.exports = withPWA({
// next.js config
reactStrictMode: true,
trailingSlash: true,
pageExtensions: ["mdx", "md", "jsx", "js", "tsx", "ts"],
i18n: {
locales: ["en"],
defaultLocale: "en",
},
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.module.rules.push({
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: "asset/resource",
});
config.module.rules.push({
test: /\.md$/,
use: "raw-loader",
});
config.module.rules.push({
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: "asset/resource",
});
config.module.rules.push({
test: /\.tsx?$/,
loader: "ts-loader",
options: {
compilerOptions: {
noEmit: false,
},
},
});
config.module.rules.push({
test: /\.js$/,
loader: "source-map-loader",
options: {
filterSourceMappingUrl: (url, resourcePath) => {
if (/.*\/node_modules\/.*/.test(resourcePath)) {
return false;
}
return true;
},
},
});
config.resolve.fallback = { fs: false };
config.resolve.extensions = [
"",
".webpack.js",
".web.js",
".ts",
".tsx",
".js",
];
config.resolve.alias.https = "https-browserify";
config.resolve.alias.http = "http-browserify";
return config;
},
});
Versions
"next": "^12.1.0", "next-pwa": "^5.6.0",
@HasanBihan It seems this repo is dead and the maintainer cannot be contacted for so long now. I've made an immediate response by resurrecting this repo ImBIOS/next-pwa.