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 Bundle Analyzer, 'ANALYZE' is not recognized as an internal or external command, operable program or batch file. #281

Closed
bayswaterpc opened this issue Sep 12, 2021 · 3 comments

Comments

@bayswaterpc
Copy link

I installed a Next project with the bundle analyzer, I'm trying to run the build analyzer with the following but I get an error.

PS D:\Personal\BayswaterPC\Code\bayswaterpc-superplate-blog> yarn build:analyze     
yarn run v1.22.10
$ ANALYZE=true npm run build
'ANALYZE' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS D:\Personal\BayswaterPC\Code\bayswaterpc-superplate-blog> 

npm run build:analyze also fails with a similar message about ANALYZE.
I noticed that the next config file wasn't configured per the bundle analyze documentation. It was just the following two lines

const withPlugins = require("next-compose-plugins");

module.exports = withPlugins([], {});

The next.config.js file now looks like the following, but I'm still getting the same issue unfortunately

const withPlugins = require('next-compose-plugins')
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
})

module.exports = withPlugins([
  [withBundleAnalyzer],
  // your other plugins here
])

Full code and project can be seen here. Thanks!

@bayswaterpc
Copy link
Author

Found the solution in this stack overflow thread, it may be a windows specific issue. Specifically performing the pwershell command from this fixed it.

I had this issue for a long time too. (webpack installed globally etc. but still not recognized) It turned out that I haven't specified enviroment variable for npm (where is file webpack.cmd sitting) So I add to my Path variable

%USERPROFILE%\AppData\Roaming\npm\
If you are using Powershell, you can type the following command to effectively add to your path :

[Environment]::SetEnvironmentVariable("Path", "$env:Path;%USERPROFILE%\AppData\Roaming\npm\", "User")
IMPORTANT : Don't forget to close and re-open your powershell window in order to apply this

@bayswaterpc
Copy link
Author

Apologies that did not fix it for me, but this issue is potentially related with this next issue

with-webpack-bundle-size-analyzer no longer works

@bayswaterpc
Copy link
Author

What did get it to work was this command npx cross-env ANALYZE=true yarn build hope that helps

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

1 participant