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

react-bootstrap Module not found when import any hooks #52518

Closed
1 task done
Cow258 opened this issue Jul 10, 2023 · 4 comments
Closed
1 task done

react-bootstrap Module not found when import any hooks #52518

Cow258 opened this issue Jul 10, 2023 · 4 comments
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@Cow258
Copy link
Contributor

Cow258 commented Jul 10, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.14.0
      npm: 9.3.1
      Yarn: 1.22.19
      pnpm: 8.6.3
    Relevant Packages:
      next: 13.4.9
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

https://github.com/Cow258/import-issue

https://codesandbox.io/p/github/Cow258/import-issue/main

To Reproduce

git clone [email protected]:Cow258/import-issue.git
pn i
pn dev

Describe the Bug

After #50900 added default modularizeImports config,
We are unable to import any hooks (like useAccordionButton) from react-bootstrap,
This will cause an error Module not found: Can't resolve 'react-bootstrap/useAccordionButton'
image

Maybe we should remove react-bootstrap from default modularize imports config

Compromise solution

Add the following config into next.config.js

const nextConfig = {
  webpack: config => {
    let modularizeImports = null
    config.module.rules.some(rule => (
      rule.oneOf?.some(oneOf => {
        modularizeImports = oneOf?.use?.options?.nextConfig?.modularizeImports
        return modularizeImports
      })
    ))
    if (modularizeImports?.['react-bootstrap'])
      delete modularizeImports['react-bootstrap']
    return config
  }
}

Expected Behavior

We can import any components and hooks from react-bootstrap

Which browser are you using? (if relevant)

Chrome 114.0.5735.198

How are you deploying your application? (if relevant)

Vercel

NEXT-1425

@Cow258 Cow258 added the bug Issue was opened via the bug report template. label Jul 10, 2023
@Cow258 Cow258 changed the title react-bootstrap Module not found when import use hook react-bootstrap Module not found when import hooks Jul 10, 2023
@Cow258 Cow258 changed the title react-bootstrap Module not found when import hooks react-bootstrap Module not found when import any hooks Jul 10, 2023
@balazsorban44 balazsorban44 added linear: next Confirmed issue that is tracked by the Next.js team. area: Ecosystem labels Jul 11, 2023
@balazsorban44
Copy link
Member

Correct, looks like this hook is imported from a file with a different name: https://github.com/react-bootstrap/react-bootstrap/blob/b124070af07fa1400d5e9690bb2e35a8d3315ec4/src/index.tsx#L8-L11C9

@Super-Kenil
Copy link

I had the same issue while importing useAccordionButton.
I fixed it by importing it like this: import { useAccordionButton } from 'react-bootstrap/AccordionButton'

@shuding
Copy link
Member

shuding commented Jul 27, 2023

Fixed in #53051.

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants