N
Nuxtβ€’2y ago
oemer

How to fix "[module] is not export by [path]" error during build, when it works on development?

Here is the error I get on yarn build
ERROR "MasterDataClient" is not exported by "../../../packages/clients/dist/src/index.js", imported by "base/domains/master-data/useMasterDataApi.ts".
file: /Users/name/Documents/dev/app/frontend/app/base/domains/master-data/useMasterDataApi.ts:1:9
1: import { MasterDataClient } from "@workspace/clients"
ERROR "MasterDataClient" is not exported by "../../../packages/clients/dist/src/index.js", imported by "base/domains/master-data/useMasterDataApi.ts".
file: /Users/name/Documents/dev/app/frontend/app/base/domains/master-data/useMasterDataApi.ts:1:9
1: import { MasterDataClient } from "@workspace/clients"
I had the same error in development and fixed it with:
vite: {
optimizeDeps: {
include: ["@workspace/clients"],
},
}
vite: {
optimizeDeps: {
include: ["@workspace/clients"],
},
}
This is the index.js it cannot import:
Object.defineProperty(exports, "__esModule", { value: true });
exports.MasterDataClient = __importStar(require("./clients/master-data-client"));
//...
Object.defineProperty(exports, "__esModule", { value: true });
exports.MasterDataClient = __importStar(require("./clients/master-data-client"));
//...
yarn dev works, but yarn build fails. It's a local yarn workspace package .
5 Replies
Julien
Julienβ€’2y ago
Try to add the package within the build.transpile option of your config
πŸ‡¨πŸ‡­ Marko Bolliger <cannap>
i had something like this then i switched to pnpm forever (local and prod)
oemer
oemerOPβ€’2y ago
Problem was that my workspaces was using commonjs as the target build πŸ€¦β€β™‚οΈ I added a new tsconfig.esm.json with the correct ESNext target and now it works even without optimizeDeps. @chakraecho I tried to add it to build.transpile before, but it didn't work. @πŸ‡¨πŸ‡­ Marko Bolliger <cannap> We will hopefully switch to pnpm soon too 🀞 Sometimes I am just tired of this obscure node eco system πŸ˜„ Hope that pnpm gives us some valuable restrictions.
πŸ‡¨πŸ‡­ Marko Bolliger <cannap>
problem with pnpm is i have to put this shamefully-hoist=true in .npmrc
oemer
oemerOPβ€’2y ago
@πŸ‡¨πŸ‡­ Marko Bolliger <cannap> Ye, I think the ecosystem is unfortunately not ready to be not "shameful" πŸ˜„
Want results from more Discord servers?
Add your server