> Build error occurred Error: Cannot find module 'next-pwa/cache' - npm

I have some problem with my next.js application.
When I use any yarn/npm/next command I'm getting similar error:
> Build error occurred
Error: Cannot find module 'next-pwa/cache'
Require stack:
- D:\Criptic\next.config.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)
at mod._resolveFilename (C:\Users\carbo\AppData\Roaming\npm\node_modules\next\dist\build\webpack\require-hook.js:23:32)
at Module._load (node:internal/modules/cjs/loader:872:27)
at Module.require (node:internal/modules/cjs/loader:1092:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (D:\Criptic\next.config.js:3:24)
at Module._compile (node:internal/modules/cjs/loader:1205:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1259:10)
at Module.load (node:internal/modules/cjs/loader:1068:32)
at Module._load (node:internal/modules/cjs/loader:909:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'D:\\Criptic\\next.config.js' ]
}
This is my package.json
"scripts": {
"clean": "rimraf \"{node_modules,.next,out.cache}\"",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"prepare": "husky install"
},
"dependencies": {
"#headlessui/react": "^1.7.2",
"#hookform/resolvers": "^2.9.8",
"#tailwindcss/forms": "^0.5.3",
"#tailwindcss/typography": "^0.5.7",
"axios": "^0.27.2",
"classnames": "^2.3.2",
"date-fns": "^2.29.3",
"dayjs": "^1.11.5",
"ethers": "^5.7.1",
"framer-motion": "^7.3.6",
"jotai": "^1.8.4",
"js-cookie": "^3.0.1",
"little-state-machine": "^4.7.0",
"lodash": "^4.17.21",
"next": "12.3.1",
"next-pwa": "^5.6.0",
"next-seo": "^5.5.0",
"next-sitemap": "^3.1.22",
"next-themes": "^0.2.1",
"overlayscrollbars": "^1.13.1",
"overlayscrollbars-react": "^0.3.0",
"rc-slider": "^10.0.1",
"react": "18.2.0",
"react-countdown": "^2.3.2",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.2",
"react-hook-form": "^7.36.0",
"react-query": "^3.39.2",
"react-share": "^4.4.0",
"react-table": "^7.7.0",
"react-use": "^17.3.2",
"recharts": "2.1.12",
"swiper": "^8.4.2",
"tiny-invariant": "^1.2.0",
"uuid": "^9.0.0",
"web3modal": "^1.9.9",
"yup": "^0.32.11"
},
next-pwa is here.
This is my next.config.js
/** #type {import('next').NextConfig} */
const runtimeCaching = require('next-pwa/cache');
const withPWA = require('next-pwa')({
dest: 'public',
disable: process.env.NODE_ENV === 'development',
runtimeCaching,
});
const nextConfig = withPWA({
reactStrictMode: true,
...(process.env.NODE_ENV === 'production' && {
typescript: {
ignoreBuildErrors: true,
},
eslint: {
ignoreDuringBuilds: true,
},
}),
});
module.exports = nextConfig;
If it possible please help me. Thank you in advance for your help
I tried to find something in the documentation about this, however, the only thing that I found approximately correct is the following link, which does not have an exact solution to this problem https://nextjs.org/docs/messages/next-config-error

Related

React Native - Unable to resolve module `node_modules/react/index.js/jsx-runtime`

I'm in the process of upgrading react native and I've been stuck on the following error for the past few days:
BUNDLE ./index.ts
error: Error: Unable to resolve module
monorepo/app/node_modules/react/index.js/jsx-runtime from monorepo/mobileChat/src/screens/index.tsx:
None of these files exist:
* node_modules/react/index.js/jsx-runtime(.native|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
* node_modules/react/index.js/jsx-runtime/index(.native|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
> 1 | import React from 'react'
2 | import { Navigation } from 'react-native-navigation'
3 | import { Provider } from 'react-redux'
4 | import getStore from 'shared/store'
at ModuleResolver.resolveDependency (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:152:15)
at DependencyGraph.resolveDependency (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/node-haste/DependencyGraph.js:264:43)
at Object.resolve (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/lib/transformHelpers.js:170:21)
at resolveDependencies (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/DeltaBundler/graphOperations.js:466:33)
at processModule (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/DeltaBundler/graphOperations.js:232:31)
at async addDependency (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/DeltaBundler/graphOperations.js:361:18)
at async Promise.all (index 9)
at async processModule (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/DeltaBundler/graphOperations.js:279:3)
at async addDependency (/Users/tbrownio/repos/bloom/bloomtext-frontend/mobileChat/node_modules/metro/src/DeltaBundler/graphOperations.js:361:18)
at async Promise.all (index 3)
I'm trying to understand why the path is resolving to ...node_modules/react/index.js/jsx-runtime. I'm not what's causing the path to be created like this. the correct path should be ...node_modules/react/jsx-runtime.
Here is my package.json
{
"name": "mobileChat",
"workspaces": {
"nohoist": [
"jetifier",
"react-native",
"react-native/**",
"#react-native-community/**",
"react-native-navigation",
"react-native-onesignal",
"react-native-version-number",
"react-native-image-crop-picker",
"react-native-video",
"react-native-keyboard-aware-scroll-view",
"#sentry/**",
"#amplitude/react-native",
"react",
"#testing-library/react-native",
"#types/react-native"
]
},
"version": "3.22.0",
"private": true,
"scripts": {
"run-ios": "react-native run-ios",
"run-android": "react-native run-android",
"start": "node node_modules/react-native/local-cli/cli.js start",
"ts": "tsc --noEmit --jsx react-native --project tsconfig.json",
"ts:watch": "yarn ts --watch",
"test": "yarn jest",
"test:watch": "yarn jest --watch",
"version": "react-native-version --never-increment-build"
},
"dependencies": {
"#amplitude/react-native": "2.16.1",
"#babel/core": "^7.12.9",
"#babel/plugin-transform-runtime": "7.13.9",
"#babel/runtime": "7.12.5",
"#react-native-async-storage/async-storage": "1.15.17",
"#react-native-community/datetimepicker": "^3.5.2",
"#react-native-community/netinfo": "4.7.0",
"#react-native-community/push-notification-ios": "^1.10.0",
"#react-native-community/toolbar-android": "^0.2.1",
"#react-native-cookies/cookies": "6.0.11",
"#sentry/react-native": "4.6.1",
"#stream-io/flat-list-mvcp": "^0.10.1",
"linkify-it": "3.0.3",
"mdurl": "^1.0.1",
"prop-types": "^15.7.2",
"react": "18.1.0",
"react-native": "0.70.6",
"react-native-audio": "https://github.com/bloomapi/react-native-audio",
"react-native-bidirectional-infinite-scroll": "^0.3.3",
"react-native-deep-linking": "^2.2.0",
"react-native-get-random-values": "^1.8.0",
"react-native-image-crop-picker": "0.38.0",
"react-native-iphone-x-helper": "1.3.1",
"react-native-keyboard-aware-scroll-view": "0.9.5",
"react-native-linear-gradient": "2.5.6",
"react-native-navigation": "7.27.1",
"react-native-onesignal": "4.3.3",
"react-native-swipe-list-view": "^3.2.9",
"react-native-version-number": "0.3.6",
"react-native-video": "^6.0.0-alpha.3",
"react-redux": "7.2.2",
"redux": "4.0.5",
"redux-logger": "3.0.6",
"redux-persist": "4.10.2",
"rn-fetch-blob": "0.12.0",
"text-encoding-polyfill": "^0.6.7"
},
"devDependencies": {
"#babel/preset-env": "7.16.11",
"#testing-library/jest-native": "^4.0.1",
"#testing-library/react-hooks": "^7.0.1",
"#testing-library/react-native": "^8.0.0",
"#types/jest": "^26.0.23",
"#types/react": "^18.0.21",
"#types/react-native": "^0.70.6",
"#types/react-test-renderer": "18.0.0",
"babel-jest": "26.6.3",
"babel-plugin-module-resolver": "4.1.0",
"get-yarn-workspaces": "^1.0.2",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "0.72.3",
"react-native-version": "^4.0.0",
"react-test-renderer": "18.1.0",
"redux-devtools-extension": "^2.13.9",
"typescript": "^4.8.3"
}
}
Here's my metro.config.js
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* #format
*/
const path = require('path')
const getWorkspaces = require('get-yarn-workspaces')
const extraNodeModules = {
'mobile': path.resolve(__dirname, 'src'),
'components': 'mobile/components',
'screens': 'mobile/screens',
}
const workspaces = getWorkspaces(__dirname)
const watchFolders = [
path.resolve(__dirname, '..', 'node_modules'),
...workspaces.filter(dir => dir !== __dirname),
]
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
resolver: {
extraNodeModules,
},
watchFolders,
}
Here's my babel.config.js
const path = require('path')
module.exports = {
"presets": ["module:metro-react-native-babel-preset"],
"plugins": [
[
"module-resolver",
{
"extensions": [".ios.js", ".android.js", ".js", ".json"],
"alias": {
"react": require.resolve('react', { paths: [path.join(__dirname, './')] }),
'^react-native$': require.resolve('react-native', { paths: [path.join(__dirname, './')] }),
'^react-native/(.+)': ([, name]) => require.resolve(`react-native/${name}`, { paths: [path.join(__dirname, './')] }),
},
},
],
],
}
Been really stuck on this. Any help would greatly be appreciated.
I recently ran into the same issue when upgrading from expo SDK 45 to 46.
It turns out that completely removing the module-resolver from my babel.config.js file resolved the issue.
Even if you don't use expo, I still suggest you to investigate this way

Nuxt.js Cannot find module '#babel/preset-env/lib/utils'

I'm getting this error when trying to run yarn run dev --port=4000
Here is the error:
Module build failed (from ./node_modules/babel-loader/lib/index.js): friendly-errors 16:52:26
Error: /Users/jacob/code/artistrepublik/elite-reviews/.nuxt/client.js: Cannot find module '#babel/preset-env/lib/utils'
Require stack:
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/babel-preset-app/src/polyfills-plugin.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/babel-preset-app/src/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/config/files/module-types.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/config/files/configuration.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/config/files/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/nuxt-route-meta/dist/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/core/dist/core.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at n (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/jiti/dist/v8cache.js:2:2364)
at PluginPass.Program (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/babel-preset-app/src/polyfills-plugin.js:15:34)
at newFn (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/visitors.js:175:21)
at NodePath._call (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/path/context.js:55:20)
at NodePath.call (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/path/context.js:42:17)
at NodePath.visit (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/path/context.js:92:31)
at TraversalContext.visitQueue (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/context.js:116:16)
at TraversalContext.visitSingle (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/context.js:85:19)
at TraversalContext.visit (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/context.js:144:19)
at Function.traverse.node (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/index.js:82:17)
at traverse (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/index.js:62:12)
at transformFile (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/transformation/index.js:107:29)
at transformFile.next (<anonymous>)
friendly-errors 16:52:26
# multi ./node_modules/eventsource-polyfill/dist/browserify-eventsource.js (webpack)-hot-middleware/client.js?reload=true&timeout=30000&ansiColors=&overlayStyles=&path=%2F__webpack_hmr%2Fclient&name=client ./.nuxt/client.js
Here is my package.json:
{
"name": "my-project",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt -r dotenv/config",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"test": "jest"
},
"dependencies": {
"#nuxtjs/axios": "^5.12.5",
"#nuxtjs/dotenv": "^1.4.1",
"#nuxtjs/pwa": "^3.3.4",
"#paypal/paypal-js": "^1.0.5",
"#vue/babel-preset-app": "^4.5.10",
"core-js": "^3.8.3",
"es6-promise": "^4.1.1",
"lodash": "^4.17.20",
"moment": "latest",
"moment-timezone": "^0.5.32",
"noty": "^3.2.0-beta",
"nuxt": "^2.14.12",
"nuxt-i18n": "^6.18.0",
"nuxt-route-meta": "^1.0.3",
"nuxt": "^2.14.6",
"nuxt-i18n": "^6.15.1",
"nuxt-route-meta": "^1.0.1",
"nuxt-stripe-module": "^3.0.1",
"object-to-formdata": "^4.1.0",
"pluralize": "latest",
"vee-validate": "^3.4.5",
"sib-api-v3-sdk": "github:sendinblue/APIv3-nodejs-library",
"vue-carousel": "^0.18.0",
"vue-chartist": "^2.2.1",
"vue-material-design-icons": "^4.11.0",
"vuejs-noty": "^0.1.3",
"vue-plyr": "^7.0.0",
"vuetify-media-player": "^0.8.1"
},
"devDependencies": {
"#babel/core": "^7.12.10",
"#mdi/font": "^5.9.55",
"#nuxt/types": "^2.14.12",
"#nuxtjs/style-resources": "^1.0.0",
"#nuxtjs/vuetify": "^1.11.3",
"#vue/test-utils": "^1.1.2",
"babel-jest": "^26.6.3",
"babel-plugin-component": "^1.1.0",
"cross-env": "^5.2.0",
"dotenv": "^8.2.0",
"jest": "^26.6.3",
"material-design-icons-iconfont": "^6.1.0",
"node-sass": "^4.14.1",
"nodemon": "^1.18.9",
"sass-loader": "^7.3.1",
"vue-jest": "^3.0.4"
}
}
And here is my .babelrc:
{
"env": {
"test": {
"presets": [
[
"#babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
}
}
I have tried deleting the node_modules folder along with removing the yarn.lock file with no luck. The babel version looks correct. This error only popped up after me playing around with some code (not the package.json) - which is an unrelated error.
Any help would be appreciated!
#babel/preset-env updated,
use old version 7.12.17
https://www.npmjs.com/package/#babel/preset-env/v/7.12.17
This issue drove me crazy for a few hours too.
The solution is to add to nuxt.config.js into build section:
/*
** Build configuration
*/
build: {
babel: {
presets(env, [ preset, options ]) {
return [
[ "#babel/preset-env", options ]
]
}
},
Make sure you have that thing installed:
npm install --save-dev #babel/preset-env
or in your case with yarn
Updated:
Then I encountered another error
regeneratorRuntime is not defined
Here is working part from my config.nuxt.js
build: {
babel: {
presets({isServer}) {
const targets = isServer ? { node: 'current' } : { ie: 11 }
return [
[ require.resolve("#babel/preset-env"), { targets } ]
]
},
plugins: [
"#babel/syntax-dynamic-import",
"#babel/transform-runtime",
"#babel/transform-async-to-generator"
]
},
I did the following:
npm uninstall #babel/preset-env
npm install #babel/preset-env#7.12.13
The latest version seems to have this issue resolved, try updating Nuxt to v2.15.2
https://nuxtjs.org/docs/release-notes
lib/utils.js was dropped for #babel/preset-env#7.13.0 and above
as stated above installing the old 7.12.17 might work
for monorepos it may not be enough. upgrading nuxtjs to 2.15.x did the trick for me
I had same error when deploying to ElasticBeanstalk
Error: /var/app/current/.nuxt/client.js: Cannot find module '#babel/preset-env/lib/utils'
upgrading from "nuxt": "v2.14.12", to "nuxt": "v2.15.2", seem to have solved the problem
npm uninstall #babel/preset-env
npm install #babel/preset-env#7.12.17
I just had the same problem, There's some issue with the newest #babel/preset-env within the Nuxt.
install the old version and it should work just fine
npm i #babel/preset-env#7.12.17 -S
You can try to do:
// package.json
"devDependencies": {
+ "#babel/preset-env": "7.12.17",
"cross-env": "^5.2.0",
"css-loader": "^3.2.0",
"node-sass": "^4.14.1",
"sass-loader": "^8.0.2",
"style-loader": "^1.0.0"
},
// package-lock.json
"#babel/preset-env": {
+"version": "7.12.17",
...,
"#nuxt/babel-preset-app": {
"requires": {
"#babel/preset-env": "7.12.17",
...
}
}
}

MAC OS - Error: Cannot find module postgres driver

I just change my computer from windows to mac and tried to start my server app that based on
postgresql and got this error: Error: Cannot find module '../driver/postgres/PostgresDriver' .
i installed typeorm and pg and installed postgres and yet i get this message.
hope somebody can help me.
Full errors:
Error: Cannot find module '../driver/postgres/PostgresDriver'
Require stack:
- /Users/ohadsahar/Documents/Development/my_app/server/node_modules/typeorm/schema-builder/RdbmsSchemaBuilder.js
- /Users/ohadsahar/Documents/Development/my_app/server/node_modules/typeorm/driver/sqlserver/SqlServerDriver.js
- /Users/ohadsahar/Documents/Development/my_app/server/node_modules/typeorm/migration/MigrationExecutor.js
- /Users/ohadsahar/Documents/Development/my_app/server/node_modules/typeorm/connection/Connection.js
- /Users/ohadsahar/Documents/Development/my_app/server/node_modules/typeorm/connection/ConnectionManager.js
- /Users/ohadsahar/Documents/Development/my_app/server/node_modules/typeorm/index.js
- /Users/ohadsahar/Documents/Development/my_app/server/src/api/models/user.model.ts
- /Users/ohadsahar/Documents/Development/my_app/server/src/api/services/auth.service.ts
- /Users/ohadsahar/Documents/Development/my_app/server/src/api/controllers/auth.controller.ts
- /Users/ohadsahar/Documents/Development/my_app/server/src/api/routes/auth.routes.ts
- /Users/ohadsahar/Documents/Development/my_app/server/src/api/routes/index.ts
- /Users/ohadsahar/Documents/Development/my_app/server/src/app.ts
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/ohadsahar/Documents/Development/my_app/server/src/schema-builder/RdbmsSchemaBuilder.ts:17:1)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
Waiting for the debugger to disconnect...
This is all the errors i get
Package.json:
{
"name": "my_app_server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest",
"build": "npm run build-ts && npm run copy-static-assets",
"start": "node dist/app.js",
"build-ts": "tsc",
"watch-ts": "npm run copy-static-assets && tsc -w",
"watch-node": "nodemon",
"watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-ts\" \"npm run watch-node\"",
"run-ts": "ts-node src/app.ts",
"copy-static-assets": "ts-node copyStaticAssets.ts",
"start:idea": "ts-node $NODE_DEBUG_OPTION --ignore false src/app.ts --env=dev",
"migration:generate": "ts-node ./node_modules/typeorm/cli migration:generate -n migration -d src/migration -f ./src/config/orm.config.ts",
"migration:run": "ts-node ./node_modules/typeorm/cli migration:run -f ./src/config/orm.config.ts"
},
"author": "",
"license": "ISC",
"dependencies": {
"#sendgrid/mail": "^7.2.0",
"#types/bcryptjs": "^2.4.2",
"#types/node": "12.11.7",
"#types/passport": "1.0.0",
"aws-sdk": "2.463.0",
"bcrypt-nodejs": "0.0.3",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"chance": "^1.1.4",
"class-transformer": "^0.2.3",
"class-validator": "^0.11.0",
"concurrently": "^4.1.0",
"cors": "^2.8.5",
"del": "^4.1.1",
"dotenv": "^8.0.0",
"express": "^4.16.4",
"helmet": "^3.21.2",
"http-status-codes": "^1.3.0",
"lodash": "^4.17.15",
"minimist": "^1.2.0",
"moment": "^2.23.0",
"morgan": "^1.9.1",
"multer": "^1.4.2",
"mysql": "^2.16.0",
"nodemailer": "^5.0.0",
"nodemailer-sendgrid-transport": "^0.2.0",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"pg": "^8.0.3",
"plivo": "^4.6.0",
"reflect-metadata": "^0.1.12",
"shelljs": "^0.8.3",
"typedi": "^0.8.0",
"typeorm": "0.2.19",
"typeorm-typedi-extensions": "^0.2.1",
"winston": "^3.1.0"
},
"devDependencies": {
"#types/bcrypt-nodejs": "0.0.30",
"#types/bluebird": "^3.5.25",
"#types/cors": "2.8.6",
"#types/csv-parse": "^1.1.11",
"#types/email-templates": "^3.5.0",
"#types/express": "4.16.0",
"#types/express-serve-static-core": "4.16.0",
"#types/helmet": "0.0.42",
"#types/lodash": "^4.14.119",
"#types/minimist": "^1.2.0",
"#types/moment": "^2.13.0",
"#types/moment-timezone": "^0.5.12",
"#types/morgan": "^1.7.35",
"#types/multer": "^1.4.3",
"#types/nodemailer": "^4.6.5",
"#types/papaparse": "^4.5.7",
"#types/passport-jwt": "^3.0.1",
"#types/pug": "^2.0.4",
"#types/shelljs": "^0.8.1",
"#types/winston": "^2.4.4",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.8.0",
"typescript": "^3.7.5"
}
}

React Native Jest Error: Cannot find module 'warnOnce' from 'react-native-implementation.js'

I get this error when I run npm test. I've looked at a number of posts, solutions, etc. that suggest making edits to package.json, babel.config.js, jest.config.js and I still receive this error. I thought it could be a version issue with React Native, but I'm on the latest version 0.60.4 and it's mentioned in a few issues that this is solved in master. Perhaps I'm overlooking something, but I'm coming up short on what else it could be.
The following is the test that fails as a result:
import { geolocationRequest } from '../location';
let mockGeoCoding = jest.fn();
jest.mock('react-native-geocoding', () => ({
openURL: mockGeoCoding,
}));
describe('geolocationRequest', () => {
it('creates a properly formatted action', () => {
expect(geolocationRequest()).toMatchSnapshot();
})
})
Thoughts?
package.json
{
"name": "<app-name>",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start --config ../../../../rn-cli.config.js",
"start:ios": "react-native run-ios",
"start:android": "react-native run-android",
"clean:ios": "cd ios/ && pod deintegrate && pod install",
"clean:android": "cd android && ./gradlew clean",
"test": "jest --watch",
"test:coverage": "jest --coverage && open coverage/lcov-report/index.html",
"fix": "eslint --fix .",
"lint:ts": "tslint --fix --project ./tsconfig.json",
"lint:fix": "npm run lint:ts --fix",
"lint:check": "tslint --type-check --project"
},
"dependencies": {
"#react-native-community/async-storage": "1.4.2",
"appcenter": "1.12.2",
"appcenter-analytics": "1.12.2",
"appcenter-crashes": "1.12.2",
"axios": "^0.19.0",
"expo-font": "4.0.0",
"polyline": "0.2.0",
"react": "16.8.6",
"react-devtools": "3.6.1",
"react-native": "0.60.*",
"react-native-animatable": "1.3.2",
"react-native-auth0": "1.4.2",
"react-native-easy-grid": "0.2.1",
"react-native-elements": "1.1.0",
"react-native-geocoding": "0.3.0",
"react-native-gesture-handler": "1.3.0",
"react-native-maps": "0.24.2",
"react-native-vector-icons": "6.4.2",
"react-navigation": "3.9.1",
"react-redux": "7.1.0",
"redux": "4.0.0",
"redux-thunk": "2.3.0",
"scheduler": "0.14.0"
},
"devDependencies": {
"#babel/plugin-proposal-class-properties": "^7.5.5",
"#babel/preset-typescript": "^7.3.3",
"#types/enzyme": "^3.10.3",
"#types/enzyme-adapter-react-16": "^1.0.5",
"#types/jest": "^24.0.17",
"#types/polyline": "0.1.28",
"#types/react": "16.8.13",
"#types/react-native": "0.57.43",
"#types/react-native-auth0": "1.3.0",
"#types/react-native-vector-icons": "6.4.0",
"#types/react-redux": "^7.1.1",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1",
"babel-jest": "24.3.1",
"babel-preset-expo": "5.1.1",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"enzyme-to-json": "^3.4.0",
"eslint": "5.15.1",
"eslint-config-airbnb": "17.1.0",
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-react": "7.12.4",
"jest": "^24.3.1",
"jest-fetch-mock": "^2.1.2",
"jest-localstorage-mock": "^2.4.0",
"metro-react-native-babel-preset": "0.53.0",
"react-dom": "^16.8.6",
"react-native-typescript-transformer": "1.2.12",
"react-test-renderer": "^16.6.3",
"redux-mock-store": "^1.5.3",
"ts-jest": "^24.0.2",
"tslint": "5.16.0",
"typescript": "3.4.3"
},
"jest": {
"preset": "react-native"
}
}
jest.config.js
module.exports = {
"preset": 'react-native',
"verbose": true,
"setupFilesAfterEnv": ["<rootDir>/__tests__/setup.js", "jest-localstorage-mock"],
"roots": [
"<rootDir>/src"
],
"transform": {
"^.+\\.tsx?$": "ts-jest",
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"testPathIgnorePatterns": ['/node_modules/'],
"snapshotSerializers": ["enzyme-to-json/serializer"],
// "collectCoverageFrom": ["src/**/*.tsx"],
"collectCoverage": true,
};
babel.config.js
module.exports = {
"presets": ["module:metro-react-native-babel-preset"]
}
I've been struggling with the same issue.
Based on this comment on github From harudev
[...] So I tested some files to test project, and find out "react-native.config.js" file was the reason.
If there is someone suffered this issue, try to remove file or options from one of your "*.config.js" 😅
So I did remove all of my *.config.js file and the error is now gone.
Hopefully this could help you.
Note that you can reproduce the behavior of the *.confing.js file with package.json
For me this happened at an update of RN from 0.59.10 to 0.61.4.
I tried several fixes but nothing worked.
The only workaround that I've found was to set metro.config.js as below:
const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
resolver: {
blacklistRE: blacklist([
/node_modules\/.*\/node_modules\/react-native\/.*/,
]),
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};
Source: jamalx31's answer from here:
https://github.com/facebook/react-native/issues/24065#issuecomment-537489786
The issue is reported and documented here:
https://github.com/facebook/react-native/issues/24065
and here:
https://github.com/facebook/react-native/issues/23943
Had the same error, after a good amount of soul searching (google searching)
i just ran npx react-native start oposed to runing my local react-native.

webpack fail misteriously on Linux: cannot find module

I'm using webpack for bundling react app. Everything works find on my Windows machine. But when I try to run it in the Linux server (centos 6.5) . I got following error:
[root#xxxxx]# webpack
module.js:457
throw err;
^
Error: Cannot find module './Parser.js'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (path/to/web/node_modules/htmlparser2/lib/index.js:1:76)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/path/to/web/node_modules/renderkid/lib/tools.js:4:14)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
here is my webpack configure file:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const merge = require('webpack-merge');
const validate = require('webpack-validator');
const parts = require('./libs/parts');
const PATHS = {
app:path.resolve(__dirname,'shared'),
build:path.resolve(__dirname,'build'),
css:[
//path.join(__dirname,'node_modules','purecss'),
//path.join(__dirname,'client','client.less'),
path.join(__dirname,'client','client.less')
]
};
const common = {
entry:{
app:PATHS.app,
style:PATHS.css
},
output:{
path:PATHS.build,
filename:'[name].js',
},
resolve: {
extensions: ['', '.js', '.jsx'],
},
resolveLoader: {
root: path.join(__dirname, 'node_modules')
}
};
var config;
switch (process.env.npm_lifecycle_event) {
case "build":
config = merge(common,
{
devtool: 'cheap-module-source-map',
//stats: 'errors-only',
output: {
path: PATHS.build,
filename: '[name].js',
// This is used for require.ensure. The setup
// will work without but this is useful to set.
chunkFilename: '[chunkhash].js'
}
},
parts.clean(PATHS.build),
parts.setFreeVariable(
'process.env.NODE_ENV',
'production'
),
parts.supportESSix(PATHS.app),
parts.extractBundle({
name: 'vendor',
entries: ['react','react-dom','react-router','react-addons-pure-render-mixin',
'redux','react-redux','immutable',"redux-thunk","superagent","draft-js","react-dropzone","react-modal"]
}),
parts.purifyCSS(PATHS.css),
parts.setupLess(PATHS.css),
parts.minify(),
parts.compressBundle()
);
break;
default:
config = merge(common,
{
devtool: 'source-map',
//stats: 'errors-only',
output: {
path: PATHS.build,
filename: '[name].js',
// This is used for require.ensure. The setup
// will work without but this is useful to set.
chunkFilename: '[chunkhash].js'
}
},
parts.clean(PATHS.build),
parts.setFreeVariable(
'process.env.NODE_ENV',
'production'
),
parts.supportESSix(PATHS.app),
parts.extractBundle({
name: 'vendor',
entries: ['react','react-dom','react-router','react-addons-pure-render-mixin',
'redux','react-redux','immutable',"redux-thunk","superagent","draft-js","react-dropzone","react-modal"]
}),
parts.purifyCSS(PATHS.css),
parts.setupLess(PATHS.css),
parts.minify()
);
}
module.exports = validate(config);
and finally, the package.json file :
{
"name": "bravo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"start": "webpack-dev-server"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"bootstrap": "^3.3.7",
"clean-webpack-plugin": "^0.1.10",
"compression-webpack-plugin": "^0.3.1",
"css-loader": "^0.24.0",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"html-webpack-plugin": "^2.22.0",
"less": "^2.7.1",
"less-loader": "^2.2.3",
"purecss": "^0.6.0",
"purifycss-webpack-plugin": "^2.0.3",
"semantic-ui": "^2.2.4",
"semantic-ui-less": "^2.2.4",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.15.0",
"webpack-merge": "^0.14.1",
"webpack-validator": "^2.2.7"
},
"dependencies": {
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"body-parser": "^1.15.2",
"compress": "^0.99.0",
"cookie-parser": "^1.4.3",
"csurf": "^1.9.0",
"draft-js": "^0.9.1",
"es6-promise": "^3.2.1",
"express": "^4.14.0",
"express-jwt": "^5.0.0",
"express-session": "^1.14.1",
"form-data": "^2.0.0",
"history": "^3.2.1",
"immutable": "^3.8.1",
"isomorphic-fetch": "^2.2.1",
"jsonwebtoken": "^7.1.9",
"method-override": "^2.3.6",
"mongoose": "^4.6.0",
"passport": "^0.3.2",
"passport-facebook": "^2.1.1",
"password-hash": "^1.2.2",
"q": "^1.4.1",
"react": "^15.3.2",
"react-addons-pure-render-mixin": "^15.3.1",
"react-dom": "^15.3.1",
"react-dropzone": "^3.6.0",
"react-modal": "^1.5.2",
"react-redux": "^4.4.5",
"react-router": "^2.7.0",
"redux": "^3.6.0",
"redux-immutable": "^3.0.8",
"redux-thunk": "^2.1.0",
"sanitize-html": "^1.13.0",
"superagent": "^2.3.0"
},
"babel": {
"presets": [
"es2015",
"react"
]
}
}
please point me out why I could not make it run on linux ? is there any platform specific problem that I should be aware of?