preactjs/prefresh

No "exports" main defined in @prefresh/vite/package.json

caleb-sb opened this issue · 1 comments

Attempting to build a vite-preact-typescript starter results in the following error:

$ pnpm build 

> prefresh-repro@0.0.0 build /workspace/prefresh-repro
> tsc && vite build

failed to load config from /workspace/prefresh-repro/vite.config.ts
error during build:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /workspace/prefresh-repro/node_modules/.pnpm/@preact+preset-vite@2.6.0_@babel+core@7.23.2_preact@10.18.1_vite@4.5.0/node_modules/@prefresh/vite/package.json imported from /workspace/prefresh-repro/node_modules/.pnpm/@preact+preset-vite@2.6.0_@babel+core@7.23.2_preact@10.18.1_vite@4.5.0/node_modules/@preact/preset-vite/dist/esm/index.mjs
    at new NodeError (node:internal/errors:406:5)
    at exportsNotFound (node:internal/modules/esm/resolve:268:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:542:13)
    at packageResolve (node:internal/modules/esm/resolve:772:14)
    at moduleResolve (node:internal/modules/esm/resolve:838:20)
    at defaultResolve (node:internal/modules/esm/resolve:1043:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
 ELIFECYCLE  Command failed with exit code 1.

I was able to address this my side by adding:

  "name": "@prefresh/vite",
  ...
  "exports": {
    ".": {
      "types": "./index.d.ts",
      "require": "./src/index.js",
+    "import": "./src/index.js"
    },

You can use the starter described above or this repo to reproduce

Thank you for the really fast response!