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

5 messages · Page 1 of 1 (latest)

jaunty shuttle
#

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"

I had the same error in development and fixed it with:

  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"));
//...

yarn dev works, but yarn build fails. It's a local yarn workspace package .

teal pecan
#

Try to add the package within the build.transpile option of your config

true fjord
#

i had something like this then i switched to pnpm forever (local and prod)

jaunty shuttle
#

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.

@teal pecan I tried to add it to build.transpile before, but it didn't work.
@true fjord 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.

true fjord
#

problem with pnpm is i have to put this shamefully-hoist=true
in .npmrc