andywer / threads-plugin

📦 Makes your threads.js code build with webpack out of the box.
Apache License 2.0
28 stars 6 forks source link

Does integration with CRACO require the part the docs mention about modifying babel presets? #38

Open SensationSama opened 3 years ago

SensationSama commented 3 years ago

Hey there,

I am using create-react-app configuration override and trying to get threads-plugin to load properly. I'm not exactly sure how the following code fits into my config file.

According to the doc, "when using @babel/preset-env", the following should be added:

"presets": [
  ["env", {
    "modules": false
  }]
]

The guide specifies that CRA projects do not need to add this

If you are using create-react-app or babel-preset-react-app ("presets": ["react-app"]), you are already good to go - no need to adapt the configuration. 

Although in my case "@babel/preset-env" is included in my craco.config.js; so I assume it is necessary. This is my craco webpack config:

module.exports = {
    reactScriptsVersion: "react-scripts" /* (default value) */,
    babel: {
        "presets": ["@babel/preset-env", "@babel/preset-react"],
        "plugins": ["@emotion/babel-plugin", "@babel/plugin-proposal-throw-expressions"]
    },
    webpack: {
        plugins: {
            add: [new ThreadsPlugin()]
        }
    },
    eslint: {
        enable: false,
    }
};

So for instance I tried loading it as the following:

"presets": ["@babel/preset-env", "@babel/preset-react",  ["env", {
            "modules": false
        }]],

but it does not compile. Perhaps I am just getting the syntax wrong?

Failed to compile.

./src/index.js
Error: Cannot find module 'babel-preset-env'
- Did you mean "@babel/env"?
    at Array.map (<anonymous>)

Also I figured that according to my original stack trace in the dev tools

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

that the issue is a result of a failure to interpret the workers as modules (so hopefully I am on the right track).

Any clarification would be greatly appreciated 😃

ruler501 commented 3 years ago

I'm also wondering about this and having the same issues. If I don't change anything it gives me the no instantiations warning.

SwenSchaeferjohann commented 3 years ago

@SensationSama Did you find a solution to the problem yet? Stuck with the same thingy right now.

SensationSama commented 3 years ago

Hey, I just ended up using comlink. Best of luck!

On Thu, Oct 14, 2021, 1:38 PM Swen Schäferjohann @.***> wrote:

@SensationSama https://github.com/SensationSama Did you find a solution to the problem yet? Stuck with the same thingy right now.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/andywer/threads-plugin/issues/38#issuecomment-943575380, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEFNQXDRQWRBXSDMET7UPGTUG4IQBANCNFSM4YQCAV3Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.