Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

babel-loader.plugin[0] must be a string, object, function #129

Open
csywweb opened this issue Sep 5, 2021 · 3 comments
Open

babel-loader.plugin[0] must be a string, object, function #129

csywweb opened this issue Sep 5, 2021 · 3 comments

Comments

@csywweb
Copy link

csywweb commented Sep 5, 2021

  • Operating System: MacOs 11.4
  • Node Version: 10.23.0
  • NPM Version: 6.14.8
  • webpack Version: 4.44.1
  • thread-loader Version:2.1.3

Actual Behavior

Hi, I'm trying to use thread-loader with babel-loader but I have this error:

ERROR in ./src/main.js
Module build failed (from ./node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
.plugins[0] must be a string, object, function

    at assertPluginTarget (/Users/csy/project/mei-pc-goods/node_modules/@babel/core/lib/config/validation/option-assertions.js:283:11)
    at assertPluginItem (/Users/csy/project/mei-pc-goods/node_modules/@babel/core/lib/config/validation/option-assertions.js:275:5)
    at arr.forEach (/Users/csy/project/mei-pc-goods/node_modules/@babel/core/lib/config/validation/option-assertions.js:241:30)
    at Array.forEach (<anonymous>)
    at assertPluginList (/Users/csy/project/mei-pc-goods/node_modules/@babel/core/lib/config/validation/option-assertions.js:241:9)
    at Object.keys.forEach.key (/Users/csy/project/mei-pc-goods/node_modules/@babel/core/lib/config/validation/options.js:123:5)
    at Array.forEach (<anonymous>)
    at validateNested (/Users/csy/project/mei-pc-goods/node_modules/@babel/core/lib/config/validation/options.js:96:21)
    at validate (/Users/csy/project/mei-pc-goods/node_modules/@babel/core/lib/config/validation/options.js:87:10)
    at loadPrivatePartialConfig (/Users/csy/project/mei-pc-goods/node_modules/@babel/core/lib/config/partial.js:78:50)

Code

// webpack.config.js
 module: {
        rules: [
            {
                test: /\.(js?|tsx?|ts?)$/,
                include: [
                    path.resolve(rootPath, './src'),
                    path.resolve(rootPath, './shared'),
                ],
                use:  [
                        //   'cache-loader',
                          'thread-loader',
                          {
                              loader: 'babel-loader',
                              options: {
                                  presets: ["react-app", { flow: false, typescript: true }],
                                  plugins: [
                                     slot, 
                                    "add-module-exports",
                                   "@babel/plugin-proposal-export-default-from",
                                   ["@babel/plugin-proposal-decorators", { legacy: true }],
                                   "@babel/plugin-transform-modules-commonjs",
                                  "@babel/plugin-proposal-object-rest-spread",
                                  "@babel/plugin-proposal-export-namespace-from",],
                              },
                          },
                      ]

plugin slot is my custom plugin like this:

function slot() {
     return {
        visitor: {
              Program: {
                  enter: function enter(path, state) {
                    console.log(state);
                    console.log("-----");
                    console.log(Object.keys(state));
                  }
              }
        }
    }
}

when i remove the thead-loader, everything is ok

@LeoJ-cn
Copy link

LeoJ-cn commented Aug 8, 2022

If you want to work properly, you need to modify the way the custom plugin is used like this

slot => require.resolve({YourBabelPluginPath})

@alvin0216
Copy link

alvin0216 commented Aug 9, 2022

the same problem:

webpack 5.65
react 17.0.2

image

@LeoJ-cn
Copy link

LeoJ-cn commented Aug 15, 2022

the same problem:

webpack 5.65 react 17.0.2

image

I need to look at the configuration of babel-loder, you are hiding it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants