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

yarn dev issue with new package structure #664

Closed
xbassols opened this issue Feb 2, 2022 · 20 comments · Fixed by #675
Closed

yarn dev issue with new package structure #664

xbassols opened this issue Feb 2, 2022 · 20 comments · Fixed by #675

Comments

@xbassols
Copy link

xbassols commented Feb 2, 2022

Hello,

I've been trying to port our project to the new package structure and I'm getting a problem with yarn dev inside site or yarn workspaces run dev.

When executed it requires the packages commerce and ours need to be prebuilt (because is trying to link with the dist folder).

For example the error that pops up if you run right away:

error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
Error: Cannot find module '/.../commerce/node_modules/@vercel/commerce/dist/config.cjs'

What is the optimal setup/commands to run the project with the current structure?

Thanks

@Edmondton
Copy link

@xbassols - I ended up running the build command on each workspace.

example:

yarn workspace @vercel/commerce-bigcommerce build

i did that for each of the following: "@vercel/commerce",
"@vercel/commerce-bigcommerce",
"@vercel/commerce-commercejs",
"@vercel/commerce-kibocommerce",
"@vercel/commerce-local",
"@vercel/commerce-ordercloud",
"@vercel/commerce-saleor",
"@vercel/commerce-shopify",
"@vercel/commerce-spree",
"@vercel/commerce-swell",
"@vercel/commerce-vendure"

Now i get this error: ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization in pages\index.tsx

@Edmondton
Copy link

@xbassols - got past my error with using node v16, next you would need to configure the appropriate env variable for the particular store you are using i.e. shopify etc etc

@xbassols
Copy link
Author

xbassols commented Feb 3, 2022

Fixed, so for those that happen to have the same problem:

  1. I've upgraded to node 16 although I'm not sure that is necessary needed.
  2. To run the project I need to run dev on each package. For example:
    yarn workspace @vercel/commerce run dev
    yarn workspace @vercel/commerce-local run dev
    yarn workspace next-commerce run dev

Thanks for the help!

@xbassols xbassols closed this as completed Feb 3, 2022
@tsukhu
Copy link

tsukhu commented Feb 6, 2022

@xbassols - Thanks for the input .. but I am still facing some issues
Env : Windows 10, git bash
Here are the steps

  • Step 1
yarn
  • Step 2
    Duplicate site/.env.template and rename it to site/.env.local
  • Step 3
    Set the commerce provider in the site/.env.local
    COMMERCE_PROVIDER=@vercel/commerce-local
  • Step 4
  • Ran in separate terminals
 yarn workspace @vercel/commerce run dev
yarn workspace @vercel/commerce-local run dev
yarn workspace next-commerce run dev

In the next-commerce run I get this error

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Loaded env from C:\workspace\latest\commerce\site\.env.local
error - Failed to load next.config.js, see more info here https://nextjs.org/doc
s/messages/next-config-error
Error: Cannot find module '@vercel\commerce-local\next.config'
Require stack:
- C:\workspace\latest\commerce\site\noop.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15
)
    at Function.mod._resolveFilename (C:\workspace\latest\commerce\node_modules\
next\dist\build\webpack\require-hook.js:183:28)

Am I missing some step or configuration . I just want to get this running with the local (placeholder commerce provider)

@tsukhu
Copy link

tsukhu commented Feb 6, 2022

Ok debugged it a bit and it boils down to this call in the packages\commerce\src\config.js

const commerceNextConfig = importCwd(path.join(provider, 'next.config'))

This is failing

Its probably a windows specific issue

Changing it to the hard coded value makes it work

 const commerceNextConfig = import('file:///C:/workspace/latest/commerce/packages/local/dist/next.config.cjs');

@tsukhu
Copy link

tsukhu commented Feb 7, 2022

Please see PR #670 as a possible fix

@wuyonglv
Copy link

wuyonglv commented Feb 8, 2022

@xbassols - I ended up running the build command on each workspace.

example:

yarn workspace @vercel/commerce-bigcommerce build

i did that for each of the following: "@vercel/commerce", "@vercel/commerce-bigcommerce", "@vercel/commerce-commercejs", "@vercel/commerce-kibocommerce", "@vercel/commerce-local", "@vercel/commerce-ordercloud", "@vercel/commerce-saleor", "@vercel/commerce-shopify", "@vercel/commerce-spree", "@vercel/commerce-swell", "@vercel/commerce-vendure"

Now i get this error: ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization in pages\index.tsx

Thank you for the methord. I run this code
yarn workspace @vercel/commerce run build
and it generate the missing module "/.../commerce/node_modules/@vercel/commerce/dist/config.cjs".

@lfades
Copy link
Member

lfades commented Feb 8, 2022

I'll be working today on a fix for this, TL;DR tsc --watch doesn't work properly for multi task setups, the dist folder isn't ready before next dev executes and the logs are a mess, so I'll make a PR to move away from it and into a custom watcher.

@HeavenlyEntity
Copy link

@xbassols - Thanks for the input .. but I am still facing some issues Env : Windows 10, git bash Here are the steps

  • Step 1
yarn
  • Step 2
    Duplicate site/.env.template and rename it to site/.env.local
  • Step 3
    Set the commerce provider in the site/.env.local
    COMMERCE_PROVIDER=@vercel/commerce-local
  • Step 4
  • Ran in separate terminals
 yarn workspace @vercel/commerce run dev
yarn workspace @vercel/commerce-local run dev
yarn workspace next-commerce run dev

In the next-commerce run I get this error

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Loaded env from C:\workspace\latest\commerce\site\.env.local
error - Failed to load next.config.js, see more info here https://nextjs.org/doc
s/messages/next-config-error
Error: Cannot find module '@vercel\commerce-local\next.config'
Require stack:
- C:\workspace\latest\commerce\site\noop.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15
)
    at Function.mod._resolveFilename (C:\workspace\latest\commerce\node_modules\
next\dist\build\webpack\require-hook.js:183:28)

Am I missing some step or configuration . I just want to get this running with the local (placeholder commerce provider)

yarn workspace @vercel/commerce-local run dev
yarn workspace v1.22.10
yarn run v1.22.10
$ taskr
node:internal/modules/cjs/loader:361
      throw err;
      ^

Error: Cannot find module '\node_modules\mri\lib\index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:353:19)
    at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Documents\GitHub\proj\node_modules\taskr\lib\cli\options.js:3:15)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Documents\GitHub\proj\node_modules\taskr\lib\cli\index.js:6:11)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10) {
  code: 'MODULE_NOT_FOUND',
  path: 'C:\\Documents\\GitHub\\proj\\node_modules\\mri\\package.json',
  requestPath: 'mri'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: C:\Program Files\nodejs\node.exe
Arguments: C:\Users\user\AppData\Roaming\npm\node_modules\yarn\lib\cli.js run dev
Directory: C:\Users\user\Documents\GitHub\proj\packages\local
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.

The commands didn't work 🤷‍♂️ - I just recommending everyone to checkout bump branch and fork that. It will solve all these issues.

nobody got time

@devnajam
Copy link

devnajam commented Feb 24, 2022

For windows users

change

const commerceNextConfig = importCwd(
  path.join(provider, 'next.config.cjs')
)

to

 const commerceNextConfig = importCwd(
    path.join(provider, '/dist/next.config.cjs')
  )

@mrcampbell
Copy link

@devnajam That worked!! Thank you!

@HeavenlyEntity
Copy link

HeavenlyEntity commented Mar 6, 2022

@devnajam That worked!! Thank you!

@mrcampbell Hey I tried that and I am getting MODULE_NOT_FOUND for mri do you know a fix for this? I am running it in the root directory should it be in the site directory?

Update: I ran it in the site directory and get config.cjs was not found.

@devnajam
Copy link

devnajam commented Mar 6, 2022

@devnajam That worked!! Thank you!

@mrcampbell Hey I tried that and I am getting MODULE_NOT_FOUND for mri do you know a fix for this? I am running it in the root directory should it be in the site directory?

Update: I ran it in the site directory and get config.cjs was not found.

@HeavenlyEntity Can you please tell me which operating system you are using, the code I shared above works for me on windows but when I push it to server it does not work, but switching back to original works on server and not on windows. To keep my work going I just used the processes.env.NODE_ENV to check if I am in development environment or not and then I use the old and new path respectively. This module not found error has a lot to do with the operating systems, otherwise why will the dev team leave a bug like this in the main branch of code

@devnajam
Copy link

devnajam commented Mar 6, 2022

for everyone facing this issue, please try to run the same code on Linux, Mac OS and windows and see what different results you get.

@HeavenlyEntity
Copy link

@devnajam That worked!! Thank you!

@mrcampbell Hey I tried that and I am getting MODULE_NOT_FOUND for mri do you know a fix for this? I am running it in the root directory should it be in the site directory?

Update: I ran it in the site directory and get config.cjs was not found.

@HeavenlyEntity Can you please tell me which operating system you are using, the code I shared above works for me on windows but when I push it to server it does not work, but switching back to original works on server and not on windows. To keep my work going I just used the processes.env.NODE_ENV to check if I am in development environment or not and then I use the old and new path respectively. This module not found error has a lot to do with the operating systems, otherwise why will the dev team leave a bug like this in the main branch of code

I am running Windows 10 Pro. It won't let me run the server locally it keeps giving me that same error. 🤔

@devnajam
Copy link

devnajam commented Mar 7, 2022

For windows users

change

const commerceNextConfig = importCwd(
  path.join(provider, 'next.config.cjs')
)

to

 const commerceNextConfig = importCwd(
    path.join(provider, '/dist/next.config.cjs')
  )

@HeavenlyEntity did you try this it works on windows.

@HeavenlyEntity
Copy link

HeavenlyEntity commented Mar 7, 2022

For windows users
change

const commerceNextConfig = importCwd(
  path.join(provider, 'next.config.cjs')
)

to

 const commerceNextConfig = importCwd(
    path.join(provider, '/dist/next.config.cjs')
  )

@HeavenlyEntity did you try this it works on windows.

Yes it doesn't work. The config.cjs is not even in the dist folder its in the src folder according to opening up the node_modules folder.

I get:

Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
Error: Cannot Find Module: '...node_modules\@vercel\commerce\dist\config.cjs'

Update: Ran in root folder then went back to site directory and got a different path of the module

Error: Cannot find module '...\node_modules\@vercel\commerce\dist\index.js'

@devnajam
Copy link

devnajam commented Mar 7, 2022 via email

@HeavenlyEntity
Copy link

HeavenlyEntity commented Mar 7, 2022

If you see the dist folder it is ignored by git, because it is generated when you run yarn dev in root folder. Changes made in dist folder won't have any effect.

On Mon, Mar 7, 2022, 7:55 AM Alec M @.> wrote: For windows users change const commerceNextConfig = importCwd( path.join(provider, 'next.config.cjs') ) to const commerceNextConfig = importCwd( path.join(provider, '/dist/next.config.cjs') ) @HeavenlyEntity https://github.com/HeavenlyEntity did you try this it works on windows. Yes it doesn't work. The config.cjs is not even in the dist folder its in the src folder according to opening up the node_modules folder. — Reply to this email directly, view it on GitHub <#664 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/APCXX3NZXLCRLV343A5EWE3U6VVYHANCNFSM5NLTLOOA . You are receiving this because you were mentioned.Message ID: @.>

Yeah what I'm saying is there is no dist folder. Nothing is there with that specific file name. I updated the comment. I am not sure why this repo is having so many problems just to get to run on localhost its honestly so time wasting lol.

So I have fixed the problem! I have placed a pull request in for the problematic library that they are using called mri by taskr by turbo lol. My builds work perfectly in dev without any issues after fixing this library!

[CRITITCAL] Update for NextJS Commerce Compatibility

@martin-richter-uk
Copy link

yarn workspace @vercel/commerce run dev
yarn workspace @vercel/commerce-local run dev

worked for me.

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

Successfully merging a pull request may close this issue.

9 participants