Uniswap / widgets

widgets-uniswap.vercel.app
GNU General Public License v3.0
123 stars 175 forks source link

Webpack complains about dynamic imports #596

Open TrejGun opened 1 year ago

TrejGun commented 1 year ago

Bug Description A clear and concise description of the bug.

Steps to Reproduce

  1. Buils project using webpack
WARNING in ../../node_modules/@uniswap/widgets/dist/cjs/index-4f48ae8b.cjs 21221:117-155
Critical dependency: the request of a dependency is an expression
    at CommonJsRequireContextDependency.getWarnings (~/node_modules/webpack/lib/dependencies/ContextDependency.js:104:18)
    at Compilation.reportDependencyErrorsAndWarnings (~/node_modules/webpack/lib/Compilation.js:3140:24)
    at ~/node_modules/webpack/lib/Compilation.js:2737:28
    at eval (eval at create (~/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:29:1)
    at ~/node_modules/webpack/lib/FlagDependencyExportsPlugin.js:380:10
    at ~/node_modules/neo-async/async.js:2830:7
    at Object.each (~/node_modules/neo-async/async.js:2850:39)
    at ~/node_modules/webpack/lib/FlagDependencyExportsPlugin.js:356:17
    at ~/node_modules/neo-async/async.js:2830:7
    at Object.each (~/node_modules/neo-async/async.js:2850:39)

The error is caused by the dynamic import in this line https://github.com/Uniswap/widgets/blob/main/src/i18n.tsx#L82

image

According to the doc, this error can be eliminated by adding a special comment

const catalog = await import(/* webpackPrefetch: true */ `./locales/${locale}.js`)

https://webpack.js.org/guides/code-splitting/#dynamic-imports

Expected Behavior No warnings at compile time

Additional Context Add any other context about the problem here (screenshots, whether the bug only occurs only in certain mobile/desktop/browser environments, etc.)