You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Next.js supports "type": "module" in package.json. When this property is set, next.config.js is treated as ESModule, so it needs to be import-edrather thanrequire-d. depcheck` does not take this into account and outputs an error:
Next.js webpack configuration detection failed with the following error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/project/next.config.js from /path/to/.npm/_npx/ec702ce30756237c/node_modules/depcheck/dist/special/webpack.js not supported.
Instead change the require of next.config.js in /path/to/.npm/_npx/ec702ce30756237c/node_modules/depcheck/dist/special/webpack.js to a dynamic import() which is available in all CommonJS modules.
at loadNextWebpackConfig (/path/to/.npm/_npx/ec702ce30756237c/node_modules/depcheck/dist/special/webpack.js:153:24)
at parseWebpack (/path/to/.npm/_npx/ec702ce30756237c/node_modules/depcheck/dist/special/webpack.js:187:27)
at getDependencies (/path/to/.npm/_npx/ec702ce30756237c/node_modules/depcheck/dist/check.js:71:24)
at /path/to/.npm/_npx/ec702ce30756237c/node_modules/depcheck/dist/check.js:97:32
at Array.map (<anonymous>)
at checkFile (/path/to/.npm/_npx/ec702ce30756237c/node_modules/depcheck/dist/check.js:97:18)
at ReaddirpStream.<anonymous> (/path/to/.npm/_npx/ec702ce30756237c/node_modules/depcheck/dist/check.js:126:24)
at ReaddirpStream.emit (node:events:513:28)
at ReaddirpStream._read (/path/to/.npm/_npx/ec702ce30756237c/node_modules/readdirp/index.js:143:22) {
code: 'ERR_REQUIRE_ESM'
} Support for this feature is new and experimental, please report issues at https://github.com/depcheck/depcheck/issues
This should be fixable by replacing require with await import on this line:
As a result, loadNextWebpackConfig needs to become async. Replacing require should be backwards compatible because CommonJS modules can be import-ed (but not vice versa).
cd /tmp
git clone https://github.com/blockprotocol/blockprotocol.git
cd blockprotocol
yarn install
cd apps/site; npx depcheck@latest;cd -
Versions
node -v: 16.18.0
npm -v: 8.19.2
npx depcheck@latest --version: 1.4.3
Extra info
When looking into this issue, it might also worth adding support for next.config.mjs. This file can be used in projects that don’t define "type": "module" in package.json.
The text was updated successfully, but these errors were encountered:
@Yukigamine could you open a new issue and give us all the info we need to debug this remotely? Like the output of depcheck --json and such, the template will guide you 👍
Bug Description
Next.js supports
"type": "module"
inpackage.json
. When this property is set,next.config.js
is treated as ESModule, so it needs to beimport
-edrather than
require-d.
depcheck` does not take this into account and outputs an error:This should be fixable by replacing
require
withawait import
on this line:depcheck/src/special/webpack.js
Line 166 in 5132d5e
As a result,
loadNextWebpackConfig
needs to become async. Replacingrequire
should be backwards compatible because CommonJS modules can beimport
-ed (but not vice versa).Code snippets
Discovered in https://github.com/blockprotocol/blockprotocol →
apps/site
Versions
node -v
:16.18.0
npm -v
:8.19.2
npx depcheck@latest --version
:1.4.3
Extra info
When looking into this issue, it might also worth adding support for
next.config.mjs
. This file can be used in projects that don’t define"type": "module"
inpackage.json
.The text was updated successfully, but these errors were encountered: