vikejs / vike

πŸ”¨ Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
4.13k stars 348 forks source link

"default" is not exported by "virtual:vite-plugin-ssr:empty-module", #1060

Closed mikhin closed 1 year ago

mikhin commented 1 year ago

Description

Hi! Big thanks for your work on this project. I recently started getting an error and was wondering how to fix it.

package.json

{
  "name": "tft-winnar-fs",
  "version": "0.0.0",
  "license": "MIT",
  "private": true,
  "scripts": {
    "frontend:dev": "nx run frontend:serve --verbose",
    "frontend:test": "nx run frontend:test",
    "frontend:test:update-snapshots": "nx run frontend:test -u",
    "frontend:build": "nx run frontend:build",
    "backend:dev": "nx run backend:serve",
    "backend:build": "nx run backend:build",
    "backend:start:prod": "node dist/apps/backend/main.js",
    "backend:test": "nx run backend:test",
    "backend:tsc": "tsc --noEmit --skipLibCheck -p apps/backend/tsconfig.app.json",
    "backend:db:lint": "nx run backend:db:lint",
    "backend:db:migrate": "npx prisma migrate dev --schema apps/backend/src/prisma/schema.prisma",
    "backend:db:migrate-create-only": "npx prisma migrate dev --schema apps/backend/src/prisma/schema.prisma --create-only",
    "backend:db:reset": "nx run backend:db:reset",
    "backend:db:generate": "nx run backend:db:generate",
    "format": "nx format",
    "tsc:all": "nx run-many -t tsc -t tsc-tests",
    "lint:all": "nx run-many -t lint --fix",
    "test:all": "nx run-many --target=test --all"
  },
  "dependencies": {
    "@chakra-ui/icons": "2.0.19",
    "@chakra-ui/react": "2.8.0",
    "@emotion/react": "11.11.1",
    "@emotion/styled": "11.11.0",
    "@fightmegg/riot-api": "0.0.15",
    "@fightmegg/riot-rate-limiter": "0.0.18",
    "@fontsource/poppins": "^5.0.8",
    "@nanostores/query": "0.1.3",
    "@nanostores/react": "0.7.1",
    "@nanostores/router": "0.10.0",
    "@nestjs/bull": "0.6.3",
    "@nestjs/common": "9.0.0",
    "@nestjs/config": "2.3.1",
    "@nestjs/core": "9.0.0",
    "@nestjs/platform-express": "9.0.0",
    "@prisma/client": "4.13.0",
    "@sentry/node": "^7.61.1",
    "@sentry/react": "7.52.1",
    "@sentry/tracing": "^7.61.1",
    "@swc/helpers": "0.5.0",
    "@types/lodash.last": "^3.0.7",
    "@vitest/coverage-v8": "^0.34.1",
    "bull": "4.10.4",
    "dom-to-image": "^2.6.0",
    "eslint-plugin-perfectionist": "^1.5.1",
    "express": "4.18.2",
    "framer-motion": "^10.15.1",
    "jest-mock": "29.5.0",
    "joi": "17.9.2",
    "lodash.last": "^3.0.0",
    "nanostores": "0.9.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "reflect-metadata": "0.1.13",
    "rxjs": "7.0.0",
    "tslib": "2.5.0",
    "vite-plugin-ssr": "^0.4.135"
  },
  "devDependencies": {
    "@darraghor/eslint-plugin-nestjs-typed": "3.20.5",
    "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
    "@esbuild-plugins/node-modules-polyfill": "0.2.2",
    "@nestjs/schematics": "9.0.0",
    "@nestjs/testing": "9.0.0",
    "@nx/cypress": "16.6.0",
    "@nx/eslint-plugin": "16.6.0",
    "@nx/jest": "16.6.0",
    "@nx/js": "16.6.0",
    "@nx/linter": "16.6.0",
    "@nx/nest": "16.6.0",
    "@nx/node": "16.6.0",
    "@nx/react": "16.6.0",
    "@nx/vite": "16.6.0",
    "@nx/webpack": "16.6.0",
    "@nx/workspace": "16.6.0",
    "@swc/cli": "0.1.62",
    "@swc/core": "1.3.51",
    "@testing-library/jest-dom": "5.16.5",
    "@testing-library/react": "14.0.0",
    "@types/dom-to-image": "^2.6.4",
    "@types/express": "^4.17.17",
    "@types/jest": "29.4.0",
    "@types/jsdom": "21.1.1",
    "@types/node": "18.14.2",
    "@types/react": "18.2.14",
    "@types/react-dom": "18.2.6",
    "@types/testing-library__jest-dom": "5.14.5",
    "@typescript-eslint/eslint-plugin": "5.62.0",
    "@typescript-eslint/parser": "5.62.0",
    "@vitejs/plugin-react": "4.0.4",
    "@vitest/ui": "0.31.4",
    "babel-jest": "^29.6.2",
    "cypress": "12.17.3",
    "eslint": "8.15.0",
    "eslint-config-prettier": "8.1.0",
    "eslint-import-resolver-typescript": "3.5.5",
    "eslint-plugin-cypress": "2.10.3",
    "eslint-plugin-import": "2.27.5",
    "eslint-plugin-jsx-a11y": "6.7.1",
    "eslint-plugin-react": "7.32.2",
    "eslint-plugin-react-hooks": "4.6.0",
    "eslint-plugin-react-refresh": "0.3.5",
    "jest": "29.4.1",
    "jest-environment-jsdom": "^29.6.2",
    "jest-environment-node": "29.4.1",
    "jsdom": "22.1.0",
    "nx": "16.6.0",
    "nx-cloud": "16.2.0",
    "prettier": "2.6.2",
    "react-test-renderer": "18.2.0",
    "ts-jest": "29.1.0",
    "ts-node": "10.9.1",
    "typescript": "5.1.6",
    "vite": "4.4.9",
    "vite-plugin-eslint": "1.8.1",
    "vite-tsconfig-paths": "4.2.0",
    "vitest": "0.31.4"
  },
  "pnpm": {
    "overrides": {
      "nwsapi": "2.2.2"
    }
  }
}

Log

frontend git:(main) npx vite build --emptyOutDir
vite v4.4.9 building for production...
βœ“ 1313 modules transformed.
βœ“ built in 2.51s
"default" is not exported by "virtual:vite-plugin-ssr:empty-module", imported by "src/configs/get-application-config.ts".
file: /Users/undgrnd/WebstormProjects/tft-winnar-fs/apps/frontend/src/configs/get-application-config.ts:1:7
1: import Joi from 'joi';
          ^
2: 
3: export interface ApplicationConfig {
error during build:
RollupError: "default" is not exported by "virtual:vite-plugin-ssr:empty-module", imported by "src/configs/get-application-config.ts".
    at error (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:2245:30)
    at Module.error (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:13604:16)
    at Module.traceVariable (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:14029:29)
    at ModuleScope.findVariable (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:12547:39)
    at ReturnValueScope.findVariable (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:7082:38)
    at ChildScope.findVariable (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:7082:38)
    at MemberExpression.bind (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:9482:49)
    at CallExpression.bind (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:5850:23)
    at CallExpression.bind (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:9833:15)
    at VariableDeclarator.bind (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:5850:23)

one more log

vite v4.4.9 building for production...
transforming...
βœ“ 1457 modules transformed.
βœ“ built in 2.95s
"Flex" is not exported by "virtual:vite-plugin-ssr:empty-module", imported by "src/components/ChampionStars.tsx".
file: /Users/undgrnd/WebstormProjects/tft-winnar-fs/apps/frontend/src/components/ChampionStars.tsx:2:9
1: import { StarIcon } from '@chakra-ui/icons';
2: import { Flex } from '@chakra-ui/react';
            ^
3: import { ReactElement } from 'react';
error during build:
RollupError: "Flex" is not exported by "virtual:vite-plugin-ssr:empty-module", imported by "src/components/ChampionStars.tsx".
    at error (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:2245:30)
    at Module.error (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:13604:16)
    at Module.traceVariable (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:14029:29)
    at ModuleScope.findVariable (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:12547:39)
    at ReturnValueScope.findVariable (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:7082:38)
    at ChildScope.findVariable (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:7082:38)
    at Identifier.bind (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:8267:40)
    at CallExpression.bind (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:5846:28)
    at CallExpression.bind (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:9833:15)
    at ReturnStatement.bind (file:///Users/undgrnd/WebstormProjects/tft-winnar-fs/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:5850:23)
Warning: run-commands command "vite build --emptyOutDir" exited with non-zero status code

 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

 >  NX   Ran target build for project frontend (5s)

    βœ–    1/1 failed
    βœ”    0/1 succeeded [0 read from cache]

 ELIFECYCLE  Command failed with exit code 1.

Process finished with exit code 1

vite.config

import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import ssr from 'vite-plugin-ssr/plugin';
import viteTsConfigPaths from 'vite-tsconfig-paths';

// eslint-disable-next-line import/no-default-export
export default defineConfig({
  build: {
    outDir: '../../dist/apps/frontend',
  },

  cacheDir: '../../node_modules/.vite/my-app',

  optimizeDeps: {
    esbuildOptions: {
      define: {
        global: 'globalThis',
      },
      plugins: [
        NodeModulesPolyfillPlugin(),
        NodeGlobalsPolyfillPlugin({
          buffer: true,
          process: true,
        }),
      ],
    },
  },

  plugins: [
    react(),
    viteTsConfigPaths({
      root: '../../',
    }),
    ssr({
      prerender: true,
    }),
  ],

  preview: {
    host: 'localhost',
    port: 4300,
  },

  server: {
    fs: {
      allow: ['../../node_modules'],
    },
    host: 'localhost',
    port: 4200,
  },

  test: {
    cache: {
      dir: '../../node_modules/.vitest',
    },
    coverage: {
      exclude: ['**/*.test.*', 'libs'],
      provider: 'c8',
    },
    environment: 'jsdom',
    globals: true,
    include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
    setupFiles: ['test/setup.ts'],
  },
});
brillout commented 1 year ago

I'll need a minimal reproduction.

mikhin commented 1 year ago

rolled back to "vite-plugin-ssr": "0.4.133" and everything goes successfully

brillout commented 1 year ago

That's quite unexpected. A minimal reproduction is much needed here. I'll probably be able to quickly fix it as not much changed in that space between 133 and 135.

ArthurSaenz commented 1 year ago

rolled back to "vite-plugin-ssr": "0.4.133" and everything goes successfully

The same situation.

brillout commented 1 year ago

Please someone provide a reproduction.

brillout commented 1 year ago

Closing. I'll re-open once someone provides a reproduction.

marviobezerra commented 1 year ago

Same error.

It works fine

npm run dev

It does not work

npm run build
"initReactI18next" is not exported by "virtual:vite-plugin-ssr:empty-module", imported by "services/i18n.ts".
file: /foo/bar/vite-ssr/apps/client-web/services/i18n.ts:5:9
3: import LanguageDetector from 'i18next-browser-languagedetector';
4: import resourcesToBackend from 'i18next-resources-to-backend';
5: import { initReactI18next } from 'react-i18next';
            ^
6: 
7: const locales = ['en', 'pt'];
error during build:
RollupError: "initReactI18next" is not exported by "virtual:vite-plugin-ssr:empty-module", imported by "services/i18n.ts".
    at error (file:///foo/bar/vite-ssr/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
    at Module.error (file:///foo/bar/vite-ssr/node_modules/rollup/dist/es/shared/node-entry.js:13716:16)
    at Module.traceVariable (file:///foo/bar/vite-ssr/node_modules/rollup/dist/es/shared/node-entry.js:14146:29)
    at ModuleScope.findVariable (file:///foo/bar/vite-ssr/node_modules/rollup/dist/es/shared/node-entry.js:12589:39)
    at ReturnValueScope.findVariable (file:///foo/bar/vite-ssr/node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
    at ChildScope.findVariable (file:///foo/bar/vite-ssr/node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
    at TrackingScope.findVariable (file:///foo/bar/vite-ssr/node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
    at BlockScope.findVariable (file:///foo/bar/vite-ssr/node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
    at Identifier.bind (file:///foo/bar/vite-ssr/node_modules/rollup/dist/es/shared/node-entry.js:8309:40)
    at CallExpression.bind (file:///foo/bar/vite-ssr/node_modules/rollup/dist/es/shared/node-entry.js:5888:28)
npm ERR! Lifecycle script `build` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: @me/client-web@0.0.0 
npm ERR!   at location: /foo/bar/vite-ssr/apps/client-web 

Repo: https://github.com/marviobezerra/vite-ssr

marviobezerra commented 1 year ago

I found the issue.

For those who may face it in the future. I added paths to my tsconfig.json. So, check your vite.config.ts and add the proper resolve aliases.

Note to self, DO NOT USE vite-tsconfig-paths plugin!!!

Check this out. https://github.com/marviobezerra/vite-ssr/pull/1/files

brillout commented 1 year ago

@marviobezerra Thanks for the reproduction and solution.

brillout commented 1 year ago

I can confirm that vite-tsconfig-paths is the issue. Using it is now forbidden in 0.4.139 and, as suggested by @marviobezerra, use vite.config.js#resolve.alias instead.