vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

Not working with Yarn Plug'N'Play

Open cmark1302 opened this issue 3 years ago • 1 comments

Versions

  • originjs: v1.1.8
  • node: 14.18.0

Reproduction

Additional Details

Steps to reproduce

setup yarn Plug'N'Play project

What is Expected?

remoteEntry.js is not generating

What is actually happening?

seeing below error

transforming (2) ../../.yarn/virtual/@apollo-client-virtual-f0161762c9/0/cache/@apollo-client-npm-3.3.19-39baf9f99e-6fd1fd576b.zip/node_modules/@apollo/client/index.js(node:95242) UnhandledPromiseRejectionWarning: Error: Qualified path resolution failed - none of those files can be found on the disk.

cmark1302 avatar Aug 03 '22 18:08 cmark1302

Could you provide a repository for reproducing the problem? I can't locate the problem by your description

Jiannan-dev avatar Aug 04 '22 11:08 Jiannan-dev

Hi @ruleeeer, I' ve step into a similar issue.

I created a copy of react-vite example and just replaced package.json scripts to use yarn. Here is the repo.

Currently it does not build app. It fails with error:

yarn run v1.22.19
$ yarn workspaces run build

> app
$ vite build
vite v4.0.4 building for production...
transforming (1) ../../node_modules/react/cjs/react.production.min.jsnode:fs:590
  handleErrorFromBinding(ctx);
  
Error: ENOENT: no such file or directory, open '/Users/susanna.kosic/Dev/poc-react-vite-federated-modules/packages/app/node_modules/react/package.json'
    at Object.openSync (node:fs:590:3)
    at readFileSync (node:fs:458:35)
    at Object.buildStart (file:///Users/susanna.kosic/Dev/poc-react-vite-federated-modules/node_modules/@originjs/vite-plugin-federation/dist/index.mjs:2196:45) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/susanna.kosic/Dev/poc-react-vite-federated-modules/packages/app/node_modules/react/package.json'
}
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: /Users/susanna.kosic/.nvm/versions/node/v16.19.0/bin/node
Arguments: /opt/homebrew/Cellar/yarn/1.22.19/libexec/lib/cli.js run build
Directory: /Users/susanna.kosic/Dev/poc-react-vite-federated-modules/packages/app
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspaces for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

It seems related with app/vite.config.js and remote configuration as build succeeds when remotes are not set.

federation({
      name: 'app',
      remotes: {
        shared: 'http://localhost:5000/assets/shared.js',
      },
      shared: ['react']
    })  

susannakosic avatar Jan 07 '23 09:01 susannakosic

Hi @ruleeeer, I' ve step into a similar issue.

I created a copy of react-vite example and just replaced package.json scripts to use yarn. Here is the repo.

Currently it does not build app. It fails with error:

yarn run v1.22.19
$ yarn workspaces run build

> app
$ vite build
vite v4.0.4 building for production...
transforming (1) ../../node_modules/react/cjs/react.production.min.jsnode:fs:590
  handleErrorFromBinding(ctx);
  
Error: ENOENT: no such file or directory, open '/Users/susanna.kosic/Dev/poc-react-vite-federated-modules/packages/app/node_modules/react/package.json'
    at Object.openSync (node:fs:590:3)
    at readFileSync (node:fs:458:35)
    at Object.buildStart (file:///Users/susanna.kosic/Dev/poc-react-vite-federated-modules/node_modules/@originjs/vite-plugin-federation/dist/index.mjs:2196:45) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/susanna.kosic/Dev/poc-react-vite-federated-modules/packages/app/node_modules/react/package.json'
}
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: /Users/susanna.kosic/.nvm/versions/node/v16.19.0/bin/node
Arguments: /opt/homebrew/Cellar/yarn/1.22.19/libexec/lib/cli.js run build
Directory: /Users/susanna.kosic/Dev/poc-react-vite-federated-modules/packages/app
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspaces for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

It seems related with app/vite.config.js and remote configuration as build succeeds when remotes are not set.

federation({
      name: 'app',
      remotes: {
        shared: 'http://localhost:5000/assets/shared.js',
      },
      shared: ['react']
    })  

Hi @susannakosic , I tried your project and the error was due to an incorrect inference of the path of the react package.json file.I will submit a PR to fix it

Jiannan-dev avatar Jan 12 '23 09:01 Jiannan-dev

@susannakosic Until I release a new version, here's another simple way to solve the problem, change the contents of shared in the app dir.

before

shared: ['react']

afer

shared:{
        react:{
          version:'18.0.2'
        }
      }

图片

Jiannan-dev avatar Jan 12 '23 09:01 Jiannan-dev

Thanks a lot @ruleeeer for looking into this. I pushed your suggestion and I can see now vite building both packages successfully.

One question though - I see you were able to actually preview the app. Did you apply any additional vite.config.js change?

On my side I cannot preview it. Vite preview server does not seem to pick up correctly CORS configuration and host 5001 fails to fetch shared.js from host 5000. I've already asked some help in here, but I thought since you got it right maybe I could ask you (even if it's not apparently related with vite-plugin-federation).

susannakosic avatar Jan 13 '23 07:01 susannakosic