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

Failed to compile: You may need an additional loader to handle the result of these loaders. #5

Open
hungyifang opened this issue Jul 26, 2021 · 3 comments

Comments

@hungyifang
Copy link

Hello, I'm a novice in react, and I encounter this error.
How can I solve this or what I am missing.
./node_modules/react-use-pagination/dist-module/react-use-pagination.mjs 52:85
Module parse failed: Unexpected token (52:85)
File was processed with these loaders:

  • ./node_modules/babel-loader/lib/index.js
    You may need an additional loader to handle the result of these loaders.
    |
    | case "SET_PAGESIZE":
  return limitPageBounds(rootState.totalItems, action.pageSize)(action.nextPage ?? state);

|
| case "SET_TOTALITEMS":

@msniezynski
Copy link

msniezynski commented Aug 5, 2021

I have same issue, make a dist with older syntax please

@Hwacc
Copy link

Hwacc commented Aug 9, 2021

I have same issue too.
Currently the solutions is that:

  1. You could copy out the sourcecode from dist-module/react-use-pagination.mjs to your project
    and make sure your babel configs include presets: ['@babel/preset-env'] or 'plugins' have '@babel/plugin-proposal-nullish-coalescing-operator'. (Suggested).

  2. You could remove js rules exclude: /node_modules/ in your webpack config file, it will compile all files in node_moules, so that's not suggested.

  3. Also, you could folk this repository, and write your owned esbuild config to compile '??' symbol and build moudles. Then import to your project.

  4. Wait for update 😃

@rodgracas
Copy link

rodgracas commented Sep 3, 2021

For projects bootstraped with CRA (Create React App), and don't want to eject, do these steps:

// craco.config.js
module.exports = {
  webpack: {
    configure: {
      module: {
        rules: [
          {
            test: /\.mjs$/,
            include: /node_modules/,
            type: "javascript/auto"
          }
        ]
      }
    }
  },
  babel: {
    plugins: ['@babel/plugin-proposal-nullish-coalescing-operator'],
    presets: ['@babel/preset-env']
  },
  // more options
}

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

4 participants