how to make react-native-paper work with next.js? - next.js

I installed this example https://github.com/zeit/next.js/tree/master/examples/with-react-native-web and I added react-native-paper to it , when ever I use it ,I get this error
Error: Cannot find module 'react-native'
Require stack:
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/react-native-paper/lib/commonjs/styles/fonts.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/react-native-paper/lib/commonjs/styles/DefaultTheme.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/react-native-paper/lib/commonjs/core/theming.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/react-native-paper/lib/commonjs/index.js
- /Users/amesbahi/Code/with-react-native-web-app/.next/server/static/development/pages/index.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/next/dist/next-server/server/require.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/next/dist/next-server/server/load-components.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/next/dist/next-server/server/api-utils.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/next/dist/next-server/server/next-server.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/next/dist/server/next.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/next/dist/server/lib/start-server.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/next/dist/cli/next-dev.js
- /Users/amesbahi/Code/with-react-native-web-app/node_modules/next/dist/bin/next
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:954:17)
at Function.Module._load (internal/modules/cjs/loader.js:847:27)
at Module.require (internal/modules/cjs/loader.js:1016:19)
at require (internal/modules/cjs/helpers.js:69:18)
at Object.<anonymous> (/Users/amesbahi/Code/with-react-native-web-app/node_modules/react-native-paper/lib/commonjs/styles/fonts.js:1:279)
at Module._compile (internal/modules/cjs/loader.js:1121:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
at Module.load (internal/modules/cjs/loader.js:976:32)
at Function.Module._load (internal/modules/cjs/loader.js:884:14)
at Module.require (internal/modules/cjs/loader.js:1016:19)
at require (internal/modules/cjs/helpers.js:69:18)
at Object.<anonymous> (/Users/amesbahi/Code/with-react-native-web-app/node_modules/react-native-paper/lib/commonjs/styles/DefaultTheme.js:1:282)
at Module._compile (internal/modules/cjs/loader.js:1121:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
at Module.load (internal/modules/cjs/loader.js:976:32)
at Function.Module._load (internal/modules/cjs/loader.js:884:14)
here is a copy of my repo enter link description here
I've been struggling with this for a couple of days. Hope some one can help me

I had same approach and same issue as yours.
Here is how I made React Native Paper work in Next.js.
Build Next.js and React Native for Web(RNW) with Expo.io
Check this tutorial and make sure it's running on your local
Follow the Getting Started part and Using on the Web in React Native Paper Doc, however, regarding to next.config.js, this is all you need to do.
const { withExpo } = require("#expo/next-adapter");
const withImages = require("next-images");
const withFonts = require("next-fonts");
module.exports = withExpo(
withFonts(
withImages({
projectRoot: __dirname
})
)
);
Since Expo already provides these build-in plugin to load images and fonts, you don't need to manually add any loader for your webpack, just using it and it should work.

Related

Firebase deployment works locally but not on GitHub Action

I'm trying to build a CI/CD pipeline for my project that uses Firebase Cloud Functions.
The functions code is written in TypeScript.
Deploying the code from my local MacBook works perfectly. However, when deploying the same exact code from the GitHub Action runner it fails with an error:
/home/runner/work/geonotes-backend/geonotes-backend/functions/lib/handlers/createNoteActionHandler.js:11
return sendOutput({ note_id: note?.id });
^
SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:1052:16)
at Module._compile (internal/modules/cjs/loader.js:1100:27)
at Module._compile (pkg/prelude/bootstrap.js:1394:32)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:10)
at Module.load (internal/modules/cjs/loader.js:984:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1024:19)
at Module.require (pkg/prelude/bootstrap.js:1338:31)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/home/runner/work/geonotes-backend/geonotes-backend/functions/lib/index.js:28:51)
This looks like Firebase is not accepting the optional chaining syntax, but it should since the function runs on Node.js 14.
Furthermore, the same syntax is accepted perfectly by the CLI running on my machine.
I have verified that both my machine and the GitHub runner are using the same versions:
Node.js v14.17.4
NPM v6.14.14
Firebase CLI v9.16.0
TypeScript v4.3.5
I have also tried to run my action on macos-latest instead of ubuntu-latest with no luck.
This is one of the runs that is failing, with --debug enabled:
https://github.com/emilioschepis/geonotes-backend/runs/3261106553
Does anyone have an idea about what could be wrong?

ReferenceError: navigator is not defined on "npm run build" Nextjs #andyet/simplewebrtc

I am creating video chat app with #andyet/simplewebrtc. And I am using nextjs dynamic import. Everything is working fine on localhost but when I try to create a build with "npm run build", I am getting navigator is not defined.
Build error occurred
ReferenceError: navigator is not defined
at Object. (/Users/apple/Documents/React Mac/next-webrtc/next-webrtc/node_modules/#andyet/simplewebrtc/lib/Hark.js:4:56)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object. (/Users/apple/Documents/React Mac/next-webrtc/next-webrtc/node_modules/#andyet/simplewebrtc/actions/Media.js:5:40)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) {
type: 'ReferenceError'
}
Just upgrade to #andyet/simplewebrtc version 1.30.2 and it will resolve the issue. They made the upgrade to this version before that it was not compatible with nextjs

Framer-motion import breaks page Next Js

Hi I am trying to import framer-motion into a page in Next Js.
import { motion } from "framer-motion"
This breaks the page. I get the following error in terminal:
/Users/.../Sites/.../node_modules/framer-motion/dist/es/index.js:1
export { MotionConfig, MotionConfigContext } from './context/MotionConfigContext.js';
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:931:16)
at Module._compile (internal/modules/cjs/loader.js:979:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at eval (webpack-internal:///framer-motion:1:18)
at Object.framer-motion (/Users/.../Sites/.../.next/server/pages/work.js:446:1)
at __webpack_require__ (/Users/.../Sites/.../.next/server/pages/work.js:23:31)
I can't see any documentation on this problem anywhere.
Thanks,
I hit this same error. I noticed that Framer Motion (3.10.5) and Next (10.0.9) were both updated in the last 16 hours.
I ran npm update and it fixed this error for me but note that this command updates everything in your package.
If you are worried about breaking changes try updating just the two packages framer and next - npm update framer-motion next or yarn upgrade framer-motion next
I had the same issue, You just need to update your packages.
npm update

First Example Encore - Path must be a string. Received undefined

I try to use Encore in Symfony.
First example
I run command:
./node_modules/.bin/encore dev
and this return me error:
path.js:7
throw new TypeError('Path must be a string. Received ' + inspect(path));
^
TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.join (path.js:1211:7)
at find (/www/testencore/node_modules/babel-loader/lib/resolve-rc.js:11:21)
at module.exports (/www/testencore/node_modules/#symfony/webpack-encore/lib/config/parse-runtime.js:64:47)
at Object.<anonymous> (/www/testencore/node_modules/#symfony/webpack-encore/bin/encore.js:18:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Your issue has to do with v7.1 of babel-loader. (cfr. https://github.com/symfony/webpack-encore/issues/40)
You can fix the issue by adding the following line to your package.json
"babel-loader": "7.0"
After this make sure to run yarn upgrade, webpack-encore should work again.
Note that this is a temporary fix. You should keep an eye on the github issue to see if there's a permanent fix available.
EDIT: This has been fixed since Encore 0.9.1, updating should solve the issue.

How to deal with modules inside node_modules that depends .css files?

I'm working in a project where some of dependencies are a self made UI library components.
Those components has its proper .css file. The source structure is something like this:
|- src
|-|
|- components
|-|
| Component
|-|
|- index.js
|- Component.js
|- Component.css
The same structure is published in a build folder, with each .js file transpiled for a production compatible JavaScript format.
The project I consume this module vw using React-Starter-Kit and when I try to start the service using yarn start or npm start, I get the following error:
SyntaxError: Unexpected token .
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> ([... path to my component inside node_modules]:13:15)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
/pathtomyproject/runServer.js:67
throw new Error(`Server terminated unexpectedly with code: ${code} signal: ${signal}`);
I guess the problem is about babel trying to read .css files, but I would like to know if someone have a good approach to avoid this kind of problem, using the actual boilerplate I'm using right now (React Starter Kit).
UPDATE
I forgot to mention this. If I import that module using relative path sintax:
import Component, { Styles } from '../../../node_modules/#scope/my-project/Component';
It works as expected, obviously is nice to have syntatic sugar import
Thanks.
According to your answer, I think, that import has to be:
import Styles from './Component.css',
it's necessary to add .css extension to show that it's not .js and it has to be processed by css-loaders (in case if webpack is used) or other tools.

Resources