laravel / vite-plugin

Laravel plugin for Vite.
MIT License
799 stars 151 forks source link

Package subpath './inertia-helpers' is not defined by "exports" #224

Closed Xor767 closed 1 year ago

Xor767 commented 1 year ago

Vite Plugin Version

0.7.6

Laravel Version

10.10.1

Node Version

20.1.0

NPM Version

9.6.4

Operating System

macOS

OS Version

13.3.1

Web browser and version

terminal

Running in Sail?

No

Description

Hello, in the new version of laravel-vite-plugin (0.7.6), I've got an error you fixed already in the past (with the version 0.4.0 I think).

ESLint gives me that error:
Package subpath './inertia-helpers' is not defined by "exports" in /Users/xxx/projects/www/jinx/node_modules/laravel-vite-plugin/package.json

Here is my app.tsx where the import is made: import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';

Everything was ok with the exact same code and config (node, vite, laravel...) but with laravel-vite-plugin version 0.7.4

thanks for your help

Steps To Reproduce

jessarcher commented 1 year ago

Hi @Xor767,

Could you please provide a minimal reproduction repository? There are a lot of unknowns here. It seems like you're using React and TypeScript, but we don't know how you have configured ESLint and can't replicate the issue.

Xor767 commented 1 year ago

Hi @jessarcher,

here is a reproduction repository: https://codesandbox.io/p/sandbox/laravel-vite-plugin-xf51rf?welcome=true please run the code-sample task named "npx eslint src".

in this example, you can rollback the laravel-vite-plugin version from 0.7.6 to 0.7.4 to make it work. thanks for your help.

jessarcher commented 1 year ago

Thanks, @Xor767 - I've been able to replicate the issue now.

It seems to be triggered by the eslint-import-resolver-alias package you're using.

We have a potential workaround that I'd like you to confirm for us. In your node_modules/laravel-vite-plugin/package.json file, locate the "exports" section and make the following change:

      "exports": {
          ".": {
              "import": "./dist/index.mjs",
              "require": "./dist/index.cjs",
              "types": "./dist/index.d.ts"
          },
          "./inertia-helpers": {
              "import": "./inertia-helpers/index.js",
-             "types": "./inertia-helpers/index.d.ts"
+             "types": "./inertia-helpers/index.d.ts",
+             "node": "./inertia-helpers/index.js"
          }
      },

If this solves the issue, we can tag a new release with this in place.

Xor767 commented 1 year ago

Hi @jessarcher ! yes your workaround solves the issue in my project 💪 thanks a lot!

timacdonald commented 1 year ago

I've opened a PR to address this issue.