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

Error: Cannot find module '@vercel\commerce-local\next.config' #681

Closed
radgezito opened this issue Feb 12, 2022 · 26 comments
Closed

Error: Cannot find module '@vercel\commerce-local\next.config' #681

radgezito opened this issue Feb 12, 2022 · 26 comments

Comments

@radgezito
Copy link

After cloning the project, creating the .env.local file to use @vercel/commerce-local I get an error message when I run yarn dev command

$ yarn dev
yarn run v1.22.10
$ next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - Loaded env from c:\test\commerce\site.env.local
error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
Error: Cannot find module '@vercel\commerce-local\next.config'

Require stack:

  • c:\test\commerce\site\noop.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.mod._resolveFilename (c:\test\commerce\node_modules\next\dist\build\webpack\require-hook.js:179:28)
    at resolveFileName (c:\test\commerce\node_modules\resolve-from\index.js:29:39)
    at resolveFrom (c:\test\commerce\node_modules\resolve-from\index.js:43:9)
    at module.exports (c:\test\commerce\node_modules\resolve-from\index.js:46:47)
    at module.exports (c:\test\commerce\node_modules\import-from\index.js:4:55)
    at module.exports (c:\test\commerce\node_modules\import-cwd\index.js:4:30)
    at Object.withCommerceConfig (c:\test\commerce\packages\commerce\dist\config.cjs:19:30)
    at withCommerceConfig (c:\test\commerce\site\commerce-config.js:102:15)
    at Object. (c:\test\commerce\site\next.config.js:11:18) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [ 'C:\temp\delete\commerce\site\noop.js' ]
    }
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@amir-zahedi
Copy link

After cloning the project, creating the .env.local file to use @vercel/commerce-local I get an error message when I run yarn dev command

$ yarn dev yarn run v1.22.10 $ next dev ready - started server on 0.0.0.0:3000, url: http://localhost:3000 info - Loaded env from c:\test\commerce\site.env.local error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error Error: Cannot find module '@vercel\commerce-local\next.config' Require stack:

  • c:\test\commerce\site\noop.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.mod._resolveFilename (c:\test\commerce\node_modules\next\dist\build\webpack\require-hook.js:179:28)
    at resolveFileName (c:\test\commerce\node_modules\resolve-from\index.js:29:39)
    at resolveFrom (c:\test\commerce\node_modules\resolve-from\index.js:43:9)
    at module.exports (c:\test\commerce\node_modules\resolve-from\index.js:46:47)
    at module.exports (c:\test\commerce\node_modules\import-from\index.js:4:55)
    at module.exports (c:\test\commerce\node_modules\import-cwd\index.js:4:30)
    at Object.withCommerceConfig (c:\test\commerce\packages\commerce\dist\config.cjs:19:30)
    at withCommerceConfig (c:\test\commerce\site\commerce-config.js:102:15)
    at Object. (c:\test\commerce\site\next.config.js:11:18) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [ 'C:\temp\delete\commerce\site\noop.js' ]
    }
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Following this solved my issue @radgezito
#664

@Qwertin
Copy link

Qwertin commented Feb 13, 2022

same problem, but with '@vercel\commerce-spree\next.config'

@Dev05-Telnet
Copy link

I too have the same problem while running in windows.
but it works well in Ubuntu

@MiguelMinoldo
Copy link

Same here, getting the very same issue.. any update on this?

@aubryll
Copy link

aubryll commented Feb 16, 2022

This is a quick hack and not a fix

I am using spree as my provider. To get past this issue I ended up modifying the \packages\commerce\src\config.cjs this way

      const path = require('path')
      const merge = require('deepmerge')
      const importCwd = require('import-cwd')

      function withCommerceConfig(nextConfig = {}) {
        const commerce = nextConfig.commerce || {}
        const { provider } = commerce
        const newProvider = provider.split('-')[1];
      
        if (!newProvider) {
          throw new Error(
            `The commerce provider is missing, please add a valid provider name`
          )
        }
      
        process.chdir("../");
        process.chdir("./packages")
        const commerceNextConfig = importCwd(path.join(process.cwd(),newProvider,'src', 'next.config.cjs'));
        const config = merge(nextConfig, commerceNextConfig)
        process.chdir("../");
        process.chdir("./site");
        
        config.env = config.env || {}
      
        Object.entries(config.commerce.features).forEach(([k, v]) => {
          if (v) config.env[`COMMERCE_${k.toUpperCase()}_ENABLED`] = true
        })
      
        return config
      }
      
      module.exports = { withCommerceConfig }

Code breakdown
I am not sure how the developers missed this but when you set the provider to @vercel/commerce-spree the app will try to look for a folder in packages by the name of @vercel/commerce-spree if you set your provider to spree it will complain that this is not a valid provider.

  • To benefit both worlds we get the last part after the last dash from the provider name with this line const newProvider = provider.split('-')[1];
  • From my personal experience, it uses ./site as its working directory, this makes it impossible for importCwd to find the next.config.cjs so you need to change directories using process.chdir
  • The last part is it tries to import next.config.js instead of next.config.cjs so we rename the import to next.config.cjs or rename the file to next.config.js
  • Then I ran yarn turbo run build this part did not succeed but it managed to set the right variables
  • And finally, I navigated to ./site and ran yarn dev and it worked.

@HeavenlyEntity
Copy link

HeavenlyEntity commented Feb 19, 2022

Hey @radgezito @Qwertin the best thing to do is just checkout branch bump and fork that. Fixed the all issues for me. I think this will be the best option until the devs fix up the core issue on. #515

@gregonarash
Copy link

@radgezito @Qwertin

I hope this might help. I was able to run localhost no problem, just with yarn dev in the main monorepo folder (not in /site) , it starts localhost:3000 just fine.

Where I wasted a day was getting preview deployments on git push. The builds would fail with:

"error - failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error"

What made it work is overriding the Build Command in Build & Development Settings to cd .. && yarn build

image

@sarathjasrin
Copy link

I'm facing the same issue. I couldn't run it in the local.

@Varagos
Copy link

Varagos commented Feb 21, 2022

Also facing this problem

@sarathjasrin
Copy link

Also facing this problem

#681 (comment)

Helped me to fix it for now.

@timothyk0908
Copy link

Also facing the same issue, Windows 10 fresh clone

@lukasmiller
Copy link

lukasmiller commented Mar 1, 2022

I ran into this issue as well, on a fresh clone on a Windows 11 machine this is how I fixed it:

  • Created .env.local and modified per my backend (vendure)

  • Ran the following build commands from the /site directory:

  • yarn

  • yarn workspace @vercel/commerce build

  • yarn workspace @vercel/commerce-local build

  • yarn workspace @vercel/commerce-vendure build

And finally made changes to the config.cjs file as outlined in #681 (comment)

After doing this on a fresh clone I was able to get it running without error using yarn next dev -p 8000.

@CristianCucunuba
Copy link

@aubryll Running yarn dev in the main folder instead of running it inside the /site folder in the installation process fixed the issue for me , maybe the docs are outdated after including turborepo

@OnlyC
Copy link

OnlyC commented Mar 16, 2022

@CristianCucunuba running yarn dev in the main folder still give me this error

@CrisleyAlves
Copy link

CrisleyAlves commented Mar 25, 2022

#681 (comment)

It worked for me too. Thank you.

@GarlandM
Copy link

+1 to this issue, hoping it gets fixed instead of having to rely on the workaround.

@Shaffan
Copy link
Contributor

Shaffan commented Mar 29, 2022

Trying to run this on a Windows 10 machine with the local provider and I'm running into the same issue.

I noticed that it's making changes to my tsconfig whenever I build:

image

Using #681 (comment) as a temp workaround 🙏🏻

@dominiksipowicz
Copy link
Member

Thi issue should be fixed now by #728

@ashishkpaul
Copy link

What help me, I run the command yarn in a ./packages/"api_backend_provider" then run the command yarn dev in site directory

@aubryll
Copy link

aubryll commented May 16, 2022

What help me, I run the command yarn in a ./packages/"api_backend_provider" then run the command yarn dev in site directory

@ashishkpaul run yarn dev in the root directory.

@ashishkpaul
Copy link

sir might be its not compiling in a root directory. its done within a 49ms
yarn run v1.22.18
$ turbo run dev
Done in 0.49s

@ashishkpaul
Copy link

What help me, I run the command yarn in a ./packages/"api_backend_provider" then run the command yarn dev in site directory

@ashishkpaul run yarn dev in the root directory.

sir i am using spree 4.4 , can you guide me on these errors by running the command yarn dev

next-commerce:dev: event - compiled client and server successfully in 5s (889 modules)
next-commerce:dev: getAllProducts called. Configuration:  getAllProductsVariables:  { first: 6 } config:  { locale: 'en-US', locales: [ 'en-US', 'es' ] }
next-commerce:dev: apiFetch called. query =  url =  __UNUSED__ queryData =  {
next-commerce:dev:   variables: { methodPath: 'products.list', arguments: [ {}, [Object] ] }
next-commerce:dev: } fetchOptions =  {}
next-commerce:dev: Looking for products.list in Spree Sdk.
next-commerce:dev: Checking part products.
next-commerce:dev: Calling the Spree API: GET https://stag.dingpack.com/api/v2/storefront/products?include=primary_variant%2Cvariants%2Cimages%2Coption_types%2Cvariants.option_values&per_page=6&image_transformation%5Bquality%5D=100&image_transformation%5Bsize%5D=1000x1000
next-commerce:dev: getAllPages called. Configuration:  query:  undefined userConfig:  { locale: 'en-US', locales: [ 'en-US', 'es' ] } preview:  undefined url:  undefined
next-commerce:dev: apiFetch called. query =  url =  __UNUSED__ queryData =  { variables: { methodPath: 'pages.list', arguments: [ [Object] ] } } fetchOptions =  {}
next-commerce:dev: Looking for pages.list in Spree Sdk.
next-commerce:dev: Checking part pages.
next-commerce:dev: Calling the Spree API: GET https://stag.dingpack.com/api/v2/storefront/cms_pages?per_page=500&filter%5Blocale_eq%5D=en-US
next-commerce:dev: getSiteInfo called. Configuration:  query:  undefined getSiteInfoVariables  {} config:  { locale: 'en-US', locales: [ 'en-US', 'es' ] }
next-commerce:dev: apiFetch called. query =  url =  __UNUSED__ queryData =  { variables: { methodPath: 'taxons.list', arguments: [ [Object] ] } } fetchOptions =  {}
next-commerce:dev: Looking for taxons.list in Spree Sdk.
next-commerce:dev: Checking part taxons.
next-commerce:dev: Calling the Spree API: GET https://stag.dingpack.com/api/v2/storefront/taxons?filter%5Bparent_permalink%5D=categories
next-commerce:dev: apiFetch called. query =  url =  __UNUSED__ queryData =  { variables: { methodPath: 'taxons.list', arguments: [ [Object] ] } } fetchOptions =  {}
next-commerce:dev: Looking for taxons.list in Spree Sdk.
next-commerce:dev: Checking part taxons.
next-commerce:dev: Calling the Spree API: GET https://stag.dingpack.com/api/v2/storefront/taxons?filter%5Bparent_permalink%5D=brands

@aubryll
Copy link

aubryll commented May 16, 2022

What help me, I run the command yarn in a ./packages/"api_backend_provider" then run the command yarn dev in site directory

@ashishkpaul run yarn dev in the root directory.

sir i am using spree 4.4 , can you guide me on these errors by running the command yarn dev

next-commerce:dev: event - compiled client and server successfully in 5s (889 modules)
next-commerce:dev: getAllProducts called. Configuration:  getAllProductsVariables:  { first: 6 } config:  { locale: 'en-US', locales: [ 'en-US', 'es' ] }
next-commerce:dev: apiFetch called. query =  url =  __UNUSED__ queryData =  {
next-commerce:dev:   variables: { methodPath: 'products.list', arguments: [ {}, [Object] ] }
next-commerce:dev: } fetchOptions =  {}
next-commerce:dev: Looking for products.list in Spree Sdk.
next-commerce:dev: Checking part products.
next-commerce:dev: Calling the Spree API: GET https://stag.dingpack.com/api/v2/storefront/products?include=primary_variant%2Cvariants%2Cimages%2Coption_types%2Cvariants.option_values&per_page=6&image_transformation%5Bquality%5D=100&image_transformation%5Bsize%5D=1000x1000
next-commerce:dev: getAllPages called. Configuration:  query:  undefined userConfig:  { locale: 'en-US', locales: [ 'en-US', 'es' ] } preview:  undefined url:  undefined
next-commerce:dev: apiFetch called. query =  url =  __UNUSED__ queryData =  { variables: { methodPath: 'pages.list', arguments: [ [Object] ] } } fetchOptions =  {}
next-commerce:dev: Looking for pages.list in Spree Sdk.
next-commerce:dev: Checking part pages.
next-commerce:dev: Calling the Spree API: GET https://stag.dingpack.com/api/v2/storefront/cms_pages?per_page=500&filter%5Blocale_eq%5D=en-US
next-commerce:dev: getSiteInfo called. Configuration:  query:  undefined getSiteInfoVariables  {} config:  { locale: 'en-US', locales: [ 'en-US', 'es' ] }
next-commerce:dev: apiFetch called. query =  url =  __UNUSED__ queryData =  { variables: { methodPath: 'taxons.list', arguments: [ [Object] ] } } fetchOptions =  {}
next-commerce:dev: Looking for taxons.list in Spree Sdk.
next-commerce:dev: Checking part taxons.
next-commerce:dev: Calling the Spree API: GET https://stag.dingpack.com/api/v2/storefront/taxons?filter%5Bparent_permalink%5D=categories
next-commerce:dev: apiFetch called. query =  url =  __UNUSED__ queryData =  { variables: { methodPath: 'taxons.list', arguments: [ [Object] ] } } fetchOptions =  {}
next-commerce:dev: Looking for taxons.list in Spree Sdk.
next-commerce:dev: Checking part taxons.
next-commerce:dev: Calling the Spree API: GET https://stag.dingpack.com/api/v2/storefront/taxons?filter%5Bparent_permalink%5D=brands

@ashishkpaul Where is the error? this is the same output I get on my installation, I am also using Spree 4.4. I would say ignore whatever you see there unless something is not working.

@ashishkpaul
Copy link

ashishkpaul commented May 16, 2022 via email

@ashishkpaul
Copy link

@aubryll hello sir, Front page loading successfully, but its not fetching the products from menu links

nextjs

@ashishkpaul
Copy link

resolved by adding cors nginx policies on the side of spree hosted server
https://enable-cors.org/server_nginx.html
https://docs.viblast.com/player/cors/cors-on-nginx

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