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

Next.js 12 failing with react-icons #30486

Closed
styfle opened this issue Oct 27, 2021 · 6 comments · Fixed by #30985
Closed

Next.js 12 failing with react-icons #30486

styfle opened this issue Oct 27, 2021 · 6 comments · Fixed by #30985
Assignees
Milestone

Comments

@styfle
Copy link
Member

styfle commented Oct 27, 2021

What version of Next.js are you using?

12.0.1

What version of Node.js are you using?

14

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

next build fails to bundle necessary files for react-icons

Expected Behavior

Should be able to run bundled functions from nft.json

To Reproduce

// Put this in `pages/api/index.js`

import { IconContext } from 'react-icons';
console.log(IconContext)

export default function handler(req, res) {
  res.end('it works')
}

Trace from next build is:

{
  "version": 1,
  "files": ["../webpack-runtime.js",
    "../../../package.json",
    "../../../node_modules/react-icons/lib/package.json",
    "../../../node_modules/react-icons/package.json",
    "../../../node_modules/react-icons/lib/cjs/index.js",
    "../../../node_modules/react/package.json",
    "../../../node_modules/react/index.js",
    "../../../node_modules/react-icons/lib/cjs/iconBase.js",
    "../../../node_modules/react-icons/lib/cjs/iconsManifest.js",
    "../../../node_modules/react-icons/lib/cjs/iconContext.js",
    "../../../node_modules/react/cjs/react.production.min.js",
    "../../../node_modules/object-assign/package.json",
    "../../../node_modules/object-assign/index.js"
  ]
}

The trace from nft is:

node_modules/object-assign/index.js
node_modules/object-assign/package.json
node_modules/react-icons/index.js
node_modules/react-icons/lib/cjs/iconBase.js
node_modules/react-icons/lib/cjs/iconContext.js
node_modules/react-icons/lib/cjs/iconsManifest.js
node_modules/react-icons/lib/cjs/index.js
node_modules/react-icons/lib/package.json
node_modules/react-icons/package.json
node_modules/react/cjs/react.development.js
node_modules/react/cjs/react.production.min.js
node_modules/react/index.js
node_modules/react/package.json
package.json
pages/api/index.js
pages/api/index.js

Notice the react-icons/index.js is missing from next build which causes the following:

Error: Cannot find module '/var/task/node_modules/react-icons/lib'. Please verify that the package.json has a valid "main" entry
@aboveyunhai
Copy link

@styfle I had a weird issue while using react-icons. it works but generated following warning in dev mode.
image

@Hopsken
Copy link

Hopsken commented Oct 29, 2021

Guess you shouldn't use react-icons in the api files? They are server side only. Importing react-icons here just doesn't make any sense.

@timneutkens
Copy link
Member

To temporarily work around this you can use:

// next.config.js
module.exports = {
  outputFileTracing: false
}

And remove it once this is fixed 👍

@timneutkens timneutkens added this to the 12.0.x milestone Oct 29, 2021
@ijjk
Copy link
Member

ijjk commented Nov 5, 2021

Hi, this has been updated in v12.0.3-canary.9 of Next.js, please update and give it a try!

@timneutkens
Copy link
Member

It's out on 12.0.3 now 🎉

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants