SalesforceCommerceCloud / pwa-kit

React-based JavaScript frontend framework to create a progressive web app (PWA) storefront for Salesforce B2C Commerce.
https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/pwa-kit-overview.html
BSD 3-Clause "New" or "Revised" License
282 stars 131 forks source link

[BUG] findInProjectThenSDK doesn't resolve correct path #765

Open nx-renezwinge opened 1 year ago

nx-renezwinge commented 1 year ago

Summary

We refactored our project to a MonoRepo with npm workspaces. So pwa-kit-dev in root node_modules folder. If we try to build the project, we get a lot of errors with wrong module paths. So all aliases and and rules in webpack config are broken because these are using findInProjectThenSDK and the else case creates in the path a "node_modules/node_modules", so one node_modules is too much.

Steps To Reproduce

1.) Create a npm workspaces project 2.) Add as one package the pwa-kit-app 3.) npm install in root folder 4.) Try npm run build in pwa-kit-app package

Expected result

Correct alias and rules paths. Sample: /workspaces/my-project/node_modules/react

Actual result

Paths have node_modules as path segment 2 times currently, which is broken. Sample: /workspaces/my-project/node_modules/node_modules/react

EDIT: And a last problem in webpack config.js of pwa-kit-dev. Line 333 fs.existsSync(resolve(projectDir, 'node_modules', 'pwa-kit-react-sdk')) &&

pwa-kit-react-sdk can not be found in root node_modules folder. I think if findInProjectThenSDK is fixed the resolve() should be replaced by findInProjectThenSDK()

kevinxh commented 1 year ago

Hey @nx-renezwinge , thanks for reporting the issue. I'll take this issue to the team and prioritize it.

nextor2k commented 1 year ago

@kevinxh this issue remains.

related to https://github.com/SalesforceCommerceCloud/pwa-kit/issues/869#issuecomment-1404130790

nx-renezwinge commented 2 months ago

Hello everybody :) I see the helper method was improved and is now called findDepInStack.

Problem is, it is not used for the condition check for the renderer build config const renderer = fse.existsSync(resolve(projectDir, 'node_modules', '@salesforce', 'pwa-kit-react-sdk')) && baseConfig('node')

Because of this we are forced to copy the whole config in a mono repository project structure. So it will be cool in a future version the line fse.existsSync(resolve(projectDir, 'node_modules', '@salesforce', 'pwa-kit-react-sdk')) will be replaced by findDepInStack('@salesforce/pwa-kit-react-sdk')

thx.

Best regards René