Error on build process with workspace package #15792
-
Hello I am getting an error from vite when a try to build my project, this error seem to point to a package module from my workspace. apps/front build$ cross-env NODE_ENV=production tsc && vite build --mode production
│ NODE_ENV=production is not supported in the .env file. Only NODE_ENV=development is supported to create a development build of your project. If you need to set process.env.NODE_ENV, you can…
│ vite v5.0.11 building for production...
│ transforming...
│ ✓ 2808 modules transformed.
│ [vite-plugin-pwa:build] "WebsocketMessageTypes" is not exported by "../../packages/shared/lib/index.js", imported by "src/services/app/useWebsocket.ts".
│ file: D:/Lab/Github/Friday-organisation/friday/apps/front/src/services/app/useWebsocket.ts:3:9
│ 1: import { useCallback, useRef, useState } from 'react';
│ 2:
│ 3: import { WebsocketMessageTypes, WebsocketPayload } from '@friday-ai/shared';
│ ^
│ 4:
│ 5: const port = parseInt(import.meta.env.VITE_SERVER_PORT, 10);
│ error during build:
│ RollupError: "WebsocketMessageTypes" is not exported by "../../packages/shared/lib/index.js", imported by "src/services/app/useWebsocket.ts". Obviously, the "shared" package exports the "WebsocketMessageTypes", and he work as expected on server app. Here is my vite config -> export default defineConfig({
server: {
port: Number(process.env.PORT) || 3001,
},
optimizeDeps: {
include: ['@friday-ai/shared'],
},
build: {
commonjsOptions: {
include: [/@friday-ai\/shared/, /node_modules/],
},
},
plugins: [
react(),
svgr({
svgrOptions: { exportType: 'named', ref: true, svgo: false, titleProp: true },
include: '**/*.svg',
}),
visualizer() as PluginOption,
VitePWA({
registerType: 'autoUpdate',
strategies: 'generateSW',
injectRegister: 'inline',
includeAssets: ['favicon.svg', 'favicon.ico', 'robots.txt', 'apple-touch-icon.png'],
manifest: {
name: 'Friday home assistant',
short_name: 'Friday',
start_url: '/',
display: 'standalone',
theme_color: '#ffffff',
background_color: '#ffffff',
icons: [
{
src: 'android-chrome-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: 'android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
],
},
}),
],
}); If this help, here is the repo of the project Ps: I precise if i run vite in dev mode, everything work as expected. Thansk in advance for any help ! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
(The reproduction looks quite big, so I haven't tried myself yet.) import type { WebsocketMessageTypes, WebsocketPayload } from '@friday-ai/shared This will probably ensure rollup to completely ignore imports which are not relevant during runtime. Potentially |
Beta Was this translation helpful? Give feedback.
-
Hello ! After some investigations its mean is a compatibility probleme between CommonJS and ES modules. The server app need pacakges builded as CommonJS format and the fronted app need the packages as ES module. So i'm using Parcel to build the package on both formats and voila ! Thanks @hi-ogawa for your time (your suggestion put me on the right direction to found a solution) |
Beta Was this translation helpful? Give feedback.
Hello !
After some investigations its mean is a compatibility probleme between CommonJS and ES modules. The server app need pacakges builded as CommonJS format and the fronted app need the packages as ES module.
So i'm using Parcel to build the package on both formats and voila !
Thanks @hi-ogawa for your time (your suggestion put me on the right direction to found a solution)