React Native XcodeBuild fails on header import in CI - reactjs

I am attempting to build a React Native application on an Os X CircleCI box.
My circle.yml is as follows:
machine:
xcode:
version: 8.3.3
environment:
PATH: '$PATH:$HOME/node/node-v4.4.3-darwin-x64/bin'
dependencies:
pre:
- brew install node
- npm install -g react-native-cli
- npm install
- react-native link
test:
override:
- set -o pipefail && xcodebuild -project 'ios/myApp.xcodeproj' -scheme 'myApp' clean build test -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=9.0,name=iPhone 6' CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= PROVISIONING_PROFILE= | tee $CIRCLE_ARTIFACTS/xcode_raw.log | xcpretty --color --report junit --output $CIRCLE_TEST_REPORTS/xcode/results.xml
Which fails with:
/Users/distiller/my-app/ios/myApp/AppDelegate.m:12:9: 'React/RCTBundleURLProvider.h' file not found
#import <React/RCTBundleURLProvider.h>
My package.json is follows:
{
"name": "myApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"test-watch": "jest --watch",
"test-coverage": "jest --coverage"
},
"dependencies": {
"#turf/circle": "^4.5.2",
"#turf/envelope": "^4.5.2",
"#turf/helpers": "^4.5.2",
"gl-react-native": "^2.42.3",
"react": "~15.4.0-rc.4",
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.6.1",
"react-native": "0.39.2",
"react-native-config": "0.5.0",
"react-navigation": "^1.0.0-beta.11",
"react-test-renderer": "^15.6.1"
},
"devDependencies": {
"babel-jest": "20.0.3",
"babel-preset-react-native": "2.0.0",
"enzyme": "^2.9.1",
"enzyme-to-json": "^1.5.1",
"jest": "20.0.4"
},
"rnpm": {
"assets": [
"assets/fonts"
]
},
"jest": {
"preset": "react-native",
"collectCoverageFrom": [
"src/**/*.{js,jsx}"
],
"coverageDirectory": "__coverage__",
"snapshotSerializers": [
"./node_modules/enzyme-to-json/serializer"
],
"transformIgnorePatterns": [
"node_modules/(?!react-native|native-base|react-navigation|react-native-fabric)"
],
"setupFiles": [
"./test-setup.js"
]
}
}
By running a build with ssh enabled and inspecting the version, I can say that react-native-cli is installed at 2.0.1
Interestingly, this behaviour does not exhibit when the project is built (with the exact same command) on my machine (localhost)
By googling, I have found things like: React Native 0.40.0 : RCTBundleURLProvider.h” file not found - AppDelegate.m
Describing my problem exactly, however they are all limited to RN 4.0, while my package.json is explicitly pegged at 3.9.2
Any help would be greatly appreciated!

The solution seemed to be to delete my ios/build directory. Once I did so, I started having the same behavior locally as in CircleCi (which I could then fix by simply taking React out of the import path like so:
#import <RCTBundleURLProvider.h>

I had this problem because my test script wasn't running yarn install. So a fresh clone and build would fail. You could add something like this to your config.yml file:
- run:
name: Install React Native
command: yarn install

Related

Parsing error: "parserOptions.project" has been set for #typescript-eslint/parser. The file does not match your project config: .eslintrc.js

I've just used create-react-app to start a new typescript react app and then installed firebase. I ran firebase init, selected the typescript option, enabled es lint and enabled functions.
As soon as I uncommented the boilerplate function code in functions/index.ts, I noticed some warnings in VS Code...
functions/eslintrc.js:
Giving error: "Parsing error: "parserOptions.project" has been set for #typescript-eslint/parser.
The file does not match your project config: .eslintrc.js.
The file must be included in at least one of the projects provided"
functions/tsconfig.json:
functions/src/index.ts:
giving error: "Parsing error: Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'.eslint"
functions/package.json:
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "14"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^3.9.1",
"#typescript-eslint/parser": "^3.8.0",
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.22.0",
"firebase-functions-test": "^0.2.0",
"typescript": "^3.8.0"
},
"private": true
}
I don't understand these errors. Can someone please help?
Thanks
The first error from TypeScript ESLint is related to not being able to find a project tsconfig.json that matches your functions.
To fix this, we need to tell TypeScript ESLint where the other tsconfig.json is by editing your parserOptions.
.eslintrc.js
// [...]
"parser": "#typescript-eslint/parser",
"parserOptions": {
"project": [
"./tsconfig.json",
"./functions/tsconfig.json",
]
}
// [...]
To fix the parsing issue related to JSX for your React files, you must add the jsx compiler option to your tsconfig.json configurations that include JSX. This will likely be your non-function configuration, and you will most likely need to set it to react-jsx for React v17+ or react in all other cases for Create React App.
tsconfig.json
{
"compilerOptions": {
"jsx": "react-jsx"
// [...]
}
// [...]
}
further to the above excellent suggestion by Evelyn Hathaway , and after I installed just the functions with no hosting and I changed the ".eslingrc.js: file
FROM
.eslingrc.js
parserOptions: {
project: ["tsconfig.json",
"tsconfig.dev.json"],
to
.eslingrc.js
parserOptions: {
project: ["./functions/tsconfig.json",
"./functions/tsconfig.dev.json"],
At last the seemed to work after I spent a frustrating day.....

Cannot find MDX module in Gatsby

I'm making a Gatsby site, and I've intially set it up to use markdown files via gatsby-transformer-remark. I've since decided to move it over to MDX in order to have a bit more freedom in what content I can use.
I've followed this guide to migrate the project from MD to MDX, but I keep getting the following error:
Cannot find module 'D:\XXXX\XXXX\gatsby\.cache\caches\gatsby-plugin-mdx\webpack\output.js'
Require stack:
- D:\XXXX\XXXX\gatsby\node_modules\gatsby-plugin-mdx\utils\render-html.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby-plugin-mdx\gatsby\source-nodes.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby-plugin-mdx\gatsby-node.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\bootstrap\load-plugins\validate.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\bootstrap\load-plugins\load.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\bootstrap\load-plugins\index.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\services\initialize.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\services\index.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\state-machines\develop\services.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\state-machines\develop\index.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\commands\develop-process.js
- D:\XXXX\XXXX\gatsby\.cache\tmp-4452-lp3aICfNr8bo
I've tried:
Clearing cache and build files (gatsby clean)
Updating all packages, including Gatsby itself
Various ways to include the plugin in gatsby-config.js
Changing it all back to MD, making sure it works, and then migrating it to MDX once again.
Doing a build. Same thing happens as when running gatsby develop
Deleting package-lock.json and node_modules folder and running npm install again.
Nothing worked. This has to be something really stupid to do with NPM or Webpack but I just don't see it.
gatsby-config.js
module.exports = {
siteMetadata: {
title: "XXXX",
copyright: "XXXX"
},
plugins: [
{
resolve: `gatsby-plugin-mdx`,
options: {
extensions: [`.md`, `.mdx`],
},
},
`gatsby-transformer-remark`,
`gatsby-plugin-image`,
`gatsby-plugin-sharp`,
`gatsby-transformer-sharp`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `src`,
path: `${__dirname}/src/`,
},
},
]
}
package.json
{
"name": "gatsby-starter-hello-world",
"private": true,
"description": "A simplified bare-bones starter for Gatsby",
"version": "0.1.0",
"license": "0BSD",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
},
"dependencies": {
"#mdx-js/mdx": "^1.6.22",
"#mdx-js/react": "^1.6.22",
"gatsby": "^3.1.2",
"gatsby-plugin-image": "^1.1.2",
"gatsby-plugin-mdx": "^2.1.0",
"gatsby-plugin-sharp": "^3.1.2",
"gatsby-source-filesystem": "^3.1.0",
"gatsby-transformer-remark": "^3.1.0",
"gatsby-transformer-sharp": "^3.1.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-in-viewport": "^1.0.0-alpha.16",
"react-reveal-text": "^0.1.1",
"react-spring": "^8.0.27",
"react-text-loop": "^2.3.0"
},
"devDependencies": {
"prettier": "2.2.1"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
}
}
EDIT:
I should point out that when I go that location in cache that's mentioned in the error, there really is no webpack folder, nor output.js - so it really isn't being generated when I run gatsby develop, I just can't understand why.
I've also tried making a new project by cloning the offical gatsby mdx starter template, and that is working just fine out of the box.

got Can't resolve 'react/jsx-runtime' error while use try to create the shared component with storybook in react-typescript

I tried to create a shared component using a storybook with react-redux. I am using rollup to create a shared component. due to some error unable to create the shared component.
package.json
{
"name": "story1",
"version": "0.1.0",
"private": false,
"main": "./build/index.js",
"module": "./build/index.es.js",
"peerDependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"#types/jest": "^26.0.15",
"#types/node": "^12.0.0",
"#types/react": "^16.9.53",
"#types/react-dom": "^16.9.8",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"rollup": "2.30",
"typescript": "^4.0.3",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "start-storybook -p 6006 -s public",
"build": "rollup -c",
"test": "react-scripts test",
"eject": "react-scripts eject",
"build-storybook": "build-storybook -s public"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#rollup/plugin-commonjs": "^17.0.0",
"#rollup/plugin-node-resolve": "^11.0.1",
"#storybook/addon-actions": "^6.1.11",
"#storybook/addon-essentials": "^6.1.11",
"#storybook/addon-links": "^6.1.11",
"#storybook/node-logger": "^6.1.11",
"#storybook/preset-create-react-app": "^3.1.5",
"#storybook/react": "^6.1.11",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-typescript2": "^0.29.0"
}
}
rollup.config.js
import commonjs from "#rollup/plugin-commonjs";
import resolve from "#rollup/plugin-node-resolve";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import typescript from "rollup-plugin-typescript2";
import packageJson from "./package.json";
// eslint-disable-next-line import/no-anonymous-default-export
export default {
input: "./src/index.ts",
output: [
{
file: packageJson.main,
format: "cjs",
sourcemap: true
},
{
file: packageJson.module,
format: "esm",
sourcemap: true
}
],
plugins: [peerDepsExternal(), resolve(), commonjs(), typescript()]
};
and I run the yarn add stroy1 command in my other repository.
when I try to use this component I got an error
ERROR in ./node_modules/story1/build/index.es.js
Module not found: Error: Can't resolve 'react/jsx-runtime' in '/Users/gowthamv/Documents/Workspace/my-app/node_modules/story1/build'
# ./node_modules/story1/build/index.es.js 1:0-56 47:12-15 52:12-15 52:38-42 52:98-102 52:123-126 52:245-249 52:316-319 53:36-39 54:36-39 55:24-27 56:16-19 56:47-50 56:127-131 56:132-140 56:155-158 57:28-31 62:12-16 62:41-44 63:12-16 63:41-44 64:20-24 64:84-87 64:201-204 65:20-23 66:20-24 66:44-47 67:28-31 68:20-24 68:108-111 68:286-289 69:20-24 69:84-87 69:207-210 69:329-332 69:398-401
How to fix this error?
What the React version of the project you import the component?
I got the same error and found 2 solutions
Use React < 17 & Typescript < 4.1.0 with the following tsconfig change:
"jsx": "react" // from jsx-react
Use React 17 on both the library and the other repository with
"jsx": "react-jsx"
Updating your react version possibily can resolve your problem.
Command line: npm install --save react#latest.
If you wish to specific a version, you need to run:
npm install --save react#
e.g. npm install --save react#17.0.2
I had a similar problem which i could not figure out the cause.
In order to solve this problem i
deleted the node modules and package.lock.json
deleted npm and npm-cache folder in C:\Users\user\AppData\Roaming and rebooted the PC
Then ran npm cache clean to make sure the cache was correctly cleaned.
Updated the react and react-dom version to ^17.0.0
Updated my npm version to the most recent too, perhaps this might not be a reason for the error, but i found useful to perform the update.
After that i ran:
npm install
And my project was back up and running. I believe following this might might help one with a similar problem.
I do not understand what was the main cause of the error since it occurred with no tangible reason since the project was working just fine and out of a sudden the error appeared. I believe that the file got corrupted, and i think that the new jsx transform as from react 17 kind of solved the problem, since having react in scope was not more an absolute necessity for jsx compilation. details on the new jsx transform can be read on https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html .
To solve the error "Module not found: Error: Can't resolve 'react/jsx-runtime'", make sure to update the react package by opening your terminal in your project's root directory and running the command npm install react#latest react-dom#latest and restart your dev server.
Open your terminal in your project's root directory (where your package.json file is located) and run the following commands:
👇️ with NPM
npm install react#latest react-dom#latest
👇️ ONLY If you use TypeScript
npm install --save-dev #types/react#latest #types/react-dom#latest
----------------------------------------------
👇️ with YARN
yarn add react#latest react-dom#latest
👇️ ONLY If you use TypeScript
yarn add #types/react#latest #types/react-dom#latest --dev
credits: https://bobbyhadz.com/blog/react-module-not-found-cant-resolve-react-jsx-runtime

How do I Create Electron App from existing React Project without disturbing the React Project

I have existing React Apps which are published to production web servers but I want to run them from the desktop using Electron. However, I do not want to disturb the React App package.json. I attempted to decouple an existing online tutorial by paachu on Medium but was unsuccessful. It kept failing trying to locate "main...chunk.css" and other resources needed by the React App.
With that said, I have a working React App in directory ./projx/reactApp I would like to create an Electron App in ./projx/electronApp that will build and create a packaged executable using electron-builder. The dev environment is not necessary at this time in that I only need a release package to distribute. Here is a package.json that almost works:
{
"name": "wrappedReact",
"version": "1.0.0",
"main": "./src/electron.js",
"scripts": {
"preclean": "cross-env rm -rf build",
"react-prebuild": "cross-env cp -r ../reactApp/build build",
"build-tsapp": "tsc ./src/electron.ts",
"electron-prebuild": "mv ./src/*.js ../build",
"electron-build": "npm run electron-prebuild && electron-builder",
"build": "npm run preclean && npm run electron-build",
"startdev": "concurrently \"tsc ./src/electron.ts -w\" \"cross-env
NODE_ENV=dev nodemon --exec \"\"wait-on http://localhost:3000 &&
electron src/electron.js\"\""
},
"author": "sfanjoy",
"homepage": "./",
"electron-pack": "build --em.main=build/electron.js",
"build": {
"appId": "com.example.reactApp",
"productName": "ReactApp",
"copyright": "Copyright © 2019 sfanjoy",
"files": [
"build/**/*",
"node_modules/**/*"
],
"directories": {
"buildResources": "assets"
},
"win": {
"target": "portable",
"icon": "assets/app.ico"
}
},
"dependencies": {
"#types/electron": "^1.6.10"
},
"devDependencies": {
"#types/electron": "^1.6.10",
"concurrently": "^4.1.1",
"cross-env": "^5.2.1",
"electron-builder": "^21.2.0",
"electron-is-dev": "^1.1.0",
"nodemon": "^1.19.1",
"typescript": "^3.5.2",
"wait-on": "^3.2.0"
}
}
I think the solution is with electron-builder if it would allow you to inject the ./src/electron.js into the prebuilt reactApp\dist\win-unpacked\resources\app.asar. I could then copy the reactApp/build directory, inject into the asar, and call electron-builder.
This by far (IMO) is the best starting setup (Boilerplate) I have come accross:
https://github.com/nateshmbhat/electron-react-ts-starter/

Get code coverage from Cypress with babel, nyc and istanbul plugin?

For a React/Redux project I use Cypress to test the UI. I need to get code coverage from thoses tests to have the details in Sonar (but that's another story).
So I began reading the docs from Cypress: https://docs.cypress.io/guides/tooling/code-coverage.html
I followed the instructions and found the differents plugins but nothing work. After running Cypress tests I have no coverage results and when I try to run the server with instrumented code on transpilation and try to get window.__coverage__ it's undefined.
So here is my configuration.
My devDep and NYC conf in package.json:
"devDependencies": {
"#cypress/code-coverage": "^1.8.0",
"babel-cli": "^6.26.0",
"babel-plugin-istanbul": "^5.2.0",
"babel-plugin-react-intl": "^2.4.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-react-app": "^3.1.2",
"cross-env": "^5.2.0",
"cypress": "3.1.0",
"istanbul-lib-coverage": "^2.0.5",
"jest-junit-reporter": "^1.1.0",
"junit": "^1.4.9",
"nyc": "^14.1.1",
"react-test-renderer": "^16.3.0"
[...]
},
"scripts": {
"start": "react-scripts start",
[...]
"test:unit:local": "react-scripts test --env=jsdom .*_test.js",
"test:unit": "npm run test:unit:local -- --ci --coverage --testResultsProcessor ./node_modules/jest-junit-reporter",
"test:integ:local": "cypress run --reporter junit",
"test:integ": "start-server-and-test start http://localhost:3000 test:integ:local",
"test": "cross-env NODE_ENV=test && npm run test:unit && npm run test:integ"
},
"nyc": {
"sourceMap": false,
"instrument": false
}
My .babelrc file:
{
"presets": ["#babel/preset-react"],
"plugins": [
[ "react-intl", {
"messagesDir": "./src/messages",
"extractSourceLocation": true
}],
"transform-class-properties",
"istanbul"
],
"env": {
"test": {
"plugins": [ "transform-class-properties", "istanbul" ]
}
}
}
My \cypress\support\index.js contains this line :
import '#cypress/code-coverage/support'
And here is my \cypress\plugins\index.js:
module.exports = (on, config) => {
on('task', require('#cypress/code-coverage/task'))
on('file:preprocessor', require('#cypress/code-coverage/use-babelrc'))
return config
}
So I expect to have a result like you can see on the Cypress docs.
The website is generated but the files containing coverage reports are empty.
And I don't understand what's wrong in my configuration.
Try the following line:
"start": "react-scripts -r #cypress/instrument-cra start",
I faced this issue too. Wasn't able to get code coverage. Downgrading nyc version from 14.x.x to 13.x.x fixed the problem, as mentioned here.

Resources