Git Product home page Git Product logo

Comments (13)

duyucongc avatar duyucongc commented on July 17, 2024 1

Thank you, this did solve my problem. I originally planned to use mobx directly without using the decorator.

from craco.

patricklafrance avatar patricklafrance commented on July 17, 2024

Hi @Strnadj

Have you tried this recipe? https://github.com/sharegate/craco/tree/master/recipes/use-mobx

from craco.

Strnadj avatar Strnadj commented on July 17, 2024

Yes, we have tried that, but it fails with the error message above.

from craco.

patricklafrance avatar patricklafrance commented on July 17, 2024

There is a few options for the babel decorator plugin: https://babeljs.io/docs/en/next/babel-plugin-proposal-decorators.htm

Have you tryed without the legacy option?

module.exports = {
    babel: {
        plugins: [
            ["@babel/plugin-proposal-decorators"]
        ]
    }
};

from craco.

Strnadj avatar Strnadj commented on July 17, 2024

Ok, if I delete that:

Error: [BABEL] /Users/strnadj/Projects/test/node_modules/react-dev-utils/webpackHotDevClient.js: The decorators plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean. If you want to use the legacy decorators semantics, you can set the 'legacy: true' option. (While processing: "/Users/strnadj/Projects/test/node_modules/@babel/plugin-proposal-decorators/lib/index.js")
    at Array.reduce (<anonymous>)

so I have change that to:

module.exports = {
    babel: {
        plugins: [
          ["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true } ],
        ]
    }
};

and error:

Failed to compile.

./src/index.tsx
Error: Cannot use the decorators and decorators-legacy plugin together

from craco.

patricklafrance avatar patricklafrance commented on July 17, 2024

I tryed it on my side and it works fine.

Is there something else in your setup that add the decorators-legacy plugin?

from craco.

Strnadj avatar Strnadj commented on July 17, 2024

https://github.com/Strnadj/not_working_cra there is repository, what cames in my mind... it seems to "@babel/plugin-proposal-decorators" is not ready yet for @babel 7.1..

warning "@babel/plugin-proposal-decorators > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".

not sure if it is a problem, but I was not able to find react-scripts version with @babel 7.0 in dependencies.

from craco.

patricklafrance avatar patricklafrance commented on July 17, 2024

Maybe it's the problem, if it's the case you should open an issue in the @babel/plugin-proposal-decorators repository.

For this issue, it doesn't seem to be a problem with craco.

If you find the right webpack recipe for inversify i'll be glad to help you to make it work with CRA + craco.

I will leave the issue open for a few days in case someone have a solution for you.

from craco.

duyucongc avatar duyucongc commented on July 17, 2024

Hi @patricklafrance
I use config

module.exports = {
    babel: {
        plugins: [
            ["@babel/plugin-proposal-decorators", { legacy: true }]
        ]
    }
};

and it work in craco start and craco build
but when I run craco test
It failed with error
Support for the experimental syntax 'decorators-legacy' isn't currently enabled
What should I change config to fit CRX test ?

from craco.

patricklafrance avatar patricklafrance commented on July 17, 2024

Hi @duyucongc

It works fine in my sandbox.

My version of the following packages version are:

@babel/[email protected]
@babel/[email protected]
@craco/[email protected]
@[email protected]

With the following craco.config.js file

const path = require("path");
const ConfigWebpackPlugin = require("config-webpack");
const { ESLINT_MODES, POSTCSS_MODES, paths } = require("@craco/craco");

const CSS_MODULE_LOCAL_IDENT_NAME = "[local]___[hash:base64:5]";

module.exports = {
    style: {
        modules: {
            localIdentName: CSS_MODULE_LOCAL_IDENT_NAME
        },
        css: {
            loaderOptions: {
                includePaths: ["/css-utils"]
            }
        },
        sass: {
            loaderOptions: {
                includePaths: ["/sass-utils"]
            }
        },
        postcss: {
            mode: POSTCSS_MODES.file
        }
    },
    eslint: {
        mode: ESLINT_MODES.file
    },
    webpack: {
        alias: {
            "@components": path.resolve(__dirname, `${paths.appSrc}/components/`)
        },
        plugins: [new ConfigWebpackPlugin()]
    },
    babel: {
        plugins: [
            "babel-plugin-jsx-control-statements",
            "babel-plugin-react-require",
            ["babel-plugin-react-css-modules", { generateScopedName: CSS_MODULE_LOCAL_IDENT_NAME, attributeNames: { "activeStyleName": "activeClassName" } }],
            ["@babel/plugin-proposal-decorators",  { legacy: true }]
        ],
    },
    jest: {
        configure: {
            globals: {
                "CONFIG": true
            },
            moduleNameMapper: {
                "^@components(.*)$": "<rootDir>/src/components$1"
            }
        }
    },
    plugins: [
        {
            plugin: {
                overrideJestConfig: ({ jestConfig }) => {
                    console.log(JSON.stringify(jestConfig, null, 4));
            
                    return jestConfig; 
                }
            }
        }
    ]
};

from craco.

patricklafrance avatar patricklafrance commented on July 17, 2024

@duyucongc https://www.npmjs.com/package/@craco/craco/v/3.2.2 should fix your problem .

from craco.

patricklafrance avatar patricklafrance commented on July 17, 2024

I will close this issue since there isn't any new comments for 7 days

from craco.

zhang14725804 avatar zhang14725804 commented on July 17, 2024

@patricklafrance thank you it did work for me

from craco.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.