originjs/vite-plugin-federation

React: Cannot read properties of undefined (reading 'config') in devSharedScopeCode

shinyuna opened this issue · 5 comments

Versions

  • vite-plugin-federation: v1.3.2
  • vite: v3.2.6

Reproduction

Host Application vite.config.ts

export default defineConfig(({ mode }) => {
  return {
      ...
      plugins: [
        vitePluginSentry(getSentryConfig(customMode)),
        federation({
          name: 'host',
          remotes: {
            remote: {
              external: `${process.env.VITE_APP_SHELL_REMOTE_URI}/remoteEntry.js`, // <- remoteEntry.js file is uploaded to the CDN
              externalType: 'url',
              format: 'var',
              from: 'webpack',
            },
          },
          shared: ['react', 'react-dom', '@emotion/react'],
        }),
      ],
  }
})

Running build script

"build:dev": "NODE_ENV=production vite build --mode development",

What is actually happening?

If you set vite mode to development when building bytes and start deploying, the build will fail with an error message like the one below.

[originjs:federation] Cannot read properties of undefined (reading 'config')
file: virtual:__federation__
error during build:
TypeError: Cannot read properties of undefined (reading 'config')
    at Object.devSharedScopeCode (/Users/yoong/workspace/inflearn-frontend/node_modules/.pnpm/@originjs+vite-plugin-federation@1.3.2/node_modules/@originjs/vite-plugin-federation/dist/index.js:1370:49)
    at Object.transform (/Users/yoong/workspace/inflearn-frontend/node_modules/.pnpm/@originjs+vite-plugin-federation@1.3.2/node_modules/@originjs/vite-plugin-federation/dist/index.js:1202:52)
    at Object.transform (/Users/yoong/workspace/inflearn-frontend/node_modules/.pnpm/@originjs+vite-plugin-federation@1.3.2/node_modules/@originjs/vite-plugin-federation/dist/index.js:1517:74)
    at file:///Users/yoong/workspace/inflearn-frontend/node_modules/.pnpm/rollup@2.79.1/node_modules/rollup/dist/es/shared/rollup.js:22748:40

I'm currently deploying with the -mode setting set to develop as a workaround.

I checked the internal code where the error occurs and found the following.
The object named viteDevServer does not have a config property declared.

I'm facing same issue

Same.

Vite: 4.3.9
vite-plugin-federation: 1.3.2

[originjs:federation] Cannot read properties of undefined (reading 'config')
file: virtual:__federation__
 >  NX   Cannot read properties of undefined (reading 'config')
TypeError: Cannot read properties of undefined (reading 'config')
    at Object.devSharedScopeCode ([***]/vite-mf-app/node_modules/@originjs/vite-plugin-federation/dist/index.js:1370:49)
    at Object.transform ([***]/vite-mf-app/node_modules/@originjs/vite-plugin-federation/dist/index.js:1202:52)
    at Object.transform ([***]/vite-mf-app/node_modules/@originjs/vite-plugin-federation/dist/index.js:1517:74)
    at file:///[***]/vite-mf-app/node_modules/rollup/dist/es/shared/node-entry.js:25544:40
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Just replace development mode with some words likedev can fix this.

Just replace development mode with some words likedev can fix this.

This is a temporary measure. I think we need to solve the real problems. 🥲

Was just about reporting the same issue! Glad to see the fix coming in!