Craco does not work properly with [email protected]
Asked Answered
P

3

9

After upgrading react-scripts to v5, craco start does not work properly. App starts with no error but in browser, there is a blank page and if i open inspector, i only see index.html codes not react codes. It was working well with [email protected]. Here is my local files;

package.json

{
  "name": "test-app",
  "private": true,
  "version": "0.1.0",
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "dependencies": {
    ...
    "@babel/preset-react": "^7.16.7",
    ...
    "@craco/craco": "^6.4.3",
    ...
    "babel-loader": "^8.2.3",
    ...
    "react": "^16.11.0",
    "react-dom": "^16.11.0",
    "react-scripts": "^5.0.0",
    "scriptjs": "^2.5.9",
    "single-spa": "^5.9.0",
    "single-spa-react": "^4.6.1",
  },
  "devDependencies": {
    "@babel/core": "7.7.2",
    "@babel/plugin-proposal-class-properties": "^7.12.1",
    "@babel/plugin-proposal-decorators": "^7.17.2",
    "@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
    "@babel/plugin-proposal-optional-chaining": "^7.6.0",
    "@svgr/webpack": "6.2.1",
    "@types/chance": "^1.0.8",
    "@types/jest": "^24.9.0",
    "@types/node": "^16.7.10",
    "@types/react": "^16.9.18",
    "@types/react-dom": "^16.9.5",
    "@types/react-router-dom": "^5.1.3",
    "@types/yargs": "^17.0.2",
    "@typescript-eslint/eslint-plugin": "^4.14.1",
    "@typescript-eslint/parser": "^4.14.1",
    "@webpack-cli/serve": "^1.6.1",
    "compression-webpack-plugin": "^9.2.0",
    "css-loader": "3.2.0",
    "dotenv": "^10.0.0",
    "dotenv-expand": "5.1.0",
    "dotenv-webpack": "^7.1.0",
    "env-path": "^1.0.7",
    "enzyme": "^3.10.0",
    "enzyme-adapter-react-16": "^1.15.1",
    "eslint": "^7.11.0",
    "eslint-config-airbnb": "^18.0.1",
    "eslint-config-airbnb-typescript": "^12.3.1",
    "eslint-config-react-app": "^6.0.0",
    "eslint-config-standard": "^14.1.0",
    "eslint-config-standard-jsx": "^8.1.0",
    "eslint-import-resolver-typescript": "^2.4.0",
    "eslint-loader": "^4.0.2",
    "eslint-plugin-flowtype": "5.2.0",
    "eslint-plugin-import": "^2.20.0",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-react": "^7.22.0",
    "eslint-plugin-react-hooks": "^4.2.0",
    "eslint-plugin-standard": "^4.0.1",
    "file-loader": "4.2.0",
    "react-app-rewired": "^2.2.1",
    "react-svg-loader": "^3.0.3",
    "react-test-renderer": "^16.11.0",
    "sass-loader": "8.0.0",
    "style-loader": "1.0.0",
    "systemjs-webpack-interop": "^2.3.7",
    "terser-webpack-plugin": "5.3.1",
    "tsconfig-paths-webpack-plugin": "^3.5.1",
    "url-loader": "2.2.0",
    "webpack": "^5.69.1",
    "webpack-cli": "^4.9.2",
    "webpack-manifest-plugin": "4.1.1",
    "workbox-webpack-plugin": "6.4.2",
    "yargs": "^17.1.1"
  },
  "scripts": {
    "version": "node scripts/version.js",
    "solid": "node scripts/solid.js",
    "start": "craco start",
    "build": "craco build"
  },
  "typings": "./src"
}

craco.config.ts

   export default {
      mode: 'development',
      babel: {
        plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]],
      },
      eslint: {
        enable: false,
      },
      webpack: {
        configure: (webpackConfig) => {
          // add this line
          // use System
          webpackConfig.output.libraryTarget = 'system';
          delete webpackConfig.optimization;

          webpackConfig.externals = [
            'react',
            'react-dom',
            'single-spa',
            'react-router',
            'react-router-dom',
            '@mf-experiences',
          ];

          return webpackConfig;
        },
      },
      // Adding Server
      devServer: (devServerConfig) => {
        devServerConfig.proxy = {
          '@mf-experiences': {
            target: 'path...',
            secure: false,
            changeOrigin: true,
          },
        };

        return devServerConfig;
      },
    };

src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './styles/nullifier.scss';
import './styles/index.scss';
import './tracking/facebook.ts';
import App from './App';
import * as serviceWorkerRegistration from './serviceWorkerRegistration';

const setRealVh = () => {
  document.documentElement.style.setProperty(
    '--vh',
    `${window.innerHeight * 0.01}px`
  );
};
window.addEventListener('resize', setRealVh);
document.documentElement.style.setProperty('--intensity', `${768 * 0.005}px`);

ReactDOM.render(<App />, document.getElementById('root'));


// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://cra.link/PWA
// serviceWorkerRegistration.register({
//   onUpdate: (registration) => registration.waiting.postMessage({ type: 'SKIP_WAITING' }),
// });
serviceWorkerRegistration.unregister();
Planar answered 23/2, 2022 at 9:5 Comment(0)
C
2

craco's Github readme, states that it is supporting Create React App (CRA) 4.*. By this statement, I'm assuming CRA 5 is not officially supported by craco.

However, this repository utilizes both CRA 5 and craco (but I have not verified that it is working). Use this repository to compare your setup (after verifying that the linked repositry is working), and try different settings/configs to see if you get further.

Claudette answered 23/2, 2022 at 10:5 Comment(3)
Thanks, I compared craco.config files and it seems I have some some misconfigurations in my project.Planar
That project works because there's no .scss compile required. That's specifically seems to be what's broken?Indecipherable
I check this repo. npm i is failed!Fann
H
8

It's currently available as a separate branch:

https://github.com/gsoft-inc/craco/tree/support-cra5

There is a version published on npm too:

"@craco/craco": "^7.0.0-alpha.3"

But note that they are looking for maintainers: https://github.com/gsoft-inc/craco/issues/415

Edit: They found a maintainer https://github.com/dilanx/craco/issues/426

Hereld answered 2/6, 2022 at 23:51 Comment(3)
In my case I also need to update craco-less, which is required 2.0.0 from craco 6.0.0 which we try to update to 7.0.0Dentilingual
@juxhinbleta that's a plugin so out of scope of the OPs request. A brief google search: - github.com/DocSpring/craco-less/issues/… - github.com/DocSpring/craco-less/tree/support-craco-7 I would open an issue there.Hereld
Awesome this worked for me too. I updated to 7.0.0-alpha.7 and use Yarn PnP so for my setup I had to update my .yarnrc.yml to fix a missing dep (@cspotcode/source-map-support didn't list source-map-support') and then had to also install babel-preset-react-app as a dev dep and things are working great!. .yarnrc.yml update: ``` packageExtensions: '@cspotcode/source-map-support@*': dependencies: 'source-map-support': '*' ```Horsley
C
2

craco's Github readme, states that it is supporting Create React App (CRA) 4.*. By this statement, I'm assuming CRA 5 is not officially supported by craco.

However, this repository utilizes both CRA 5 and craco (but I have not verified that it is working). Use this repository to compare your setup (after verifying that the linked repositry is working), and try different settings/configs to see if you get further.

Claudette answered 23/2, 2022 at 10:5 Comment(3)
Thanks, I compared craco.config files and it seems I have some some misconfigurations in my project.Planar
That project works because there's no .scss compile required. That's specifically seems to be what's broken?Indecipherable
I check this repo. npm i is failed!Fann
G
1

For every one stumbling across this post now, craco v7.0.0 was released on Nov. 8th and officially supports CRA 5.

Groh answered 24/11, 2022 at 10:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.