vite-plugin-federation
vite-plugin-federation copied to clipboard
Not working with Yarn Plug'N'Play
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.
Could you provide a repository for reproducing the problem? I can't locate the problem by your description
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 @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
@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'
}
}

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).