Dschungelabenteuer / vite-plugin-entry-shaking

Mimic tree-shaking behaviour when importing code from an entry file in development mode.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plugin does not support vite@5.1.0 or higher versions

fdc-viktor-luft opened this issue · comments

Describe the bug The plugin worked until version 5.0.12 of vite. Starting from version 5.1.0 it is not allowing to start the app in development mode anymore.

To Reproduce Try running the Vite dev mode with the plugin and vite@5.1.0

Expected behavior The plugin continues to function as before.

Additional context Almost immediately after starting the dev mode the following kind of error appears in the terminal:

error when starting dev server:
Error: Could not analyze entry file "...<private>..."
    at file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.3.3_vite@5.1.0/node_modules/vite-plugin-entry-shaking/dist/index.mjs:336:11
    at async Object.analyzeEntry (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.3.3_vite@5.1.0/node_modules/vite-plugin-entry-shaking/dist/index.mjs:335:3)
    at async file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.3.3_vite@5.1.0/node_modules/vite-plugin-entry-shaking/dist/index.mjs:344:7
    at async Promise.all (index 0)
    at async Object.analyzeEntries (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.3.3_vite@5.1.0/node_modules/vite-plugin-entry-shaking/dist/index.mjs:341:3)
    at async configResolved (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.3.3_vite@5.1.0/node_modules/vite-plugin-entry-shaking/dist/index.mjs:370:17)
    at async Promise.all (index 2)
    at async resolveConfig (file:///<private>/node_modules/.pnpm/vite@5.1.0_@types+node@20.11.17_sass@1.70.0/node_modules/vite/dist/node/chunks/dep-nGG-_oRu.js:67848:5)
    at async _createServer (file:///<private>/node_modules/.pnpm/vite@5.1.0_@types+node@20.11.17_sass@1.70.0/node_modules/vite/dist/node/chunks/dep-nGG-_oRu.js:64223:20)
    at async CAC.<anonymous> (file:///<private>/node_modules/.pnpm/vite@5.1.0_@types+node@20.11.17_sass@1.70.0/node_modules/vite/dist/node/cli.js:762:24)
commented

Hey! Thank's again for your feedback, there's been some work done late 2023 (and last month) to address most of the issues that were opened (including yours!). Unfortunately, I could not find much time to get it 100% ready, Apologies for the delay, I'll need to get back to it soon. In the mean time, could you by any chance test your codebase against the next branch? I've tried to run it on the simple example and did not notice any error (but as the name states, it's a rather trivial example and I may be missing something).

(If you were to test it by locally by cloning & building the next branch, please don't mind the "debugger app" that may spawn along with Vite's dev server as it is still WIP)

Will do and come back to you with the results. Thanks for the great news 👍

Can you release a "next" version using npm publish --tag next?

commented

Can you release a "next" version using npm publish --tag next?

Sure thing, here you go (before I get distracted yet again!)

I also restored the example dedicated to your issue :) Thanks a lot for you patience ! Please tell me if anything goes wrong as there are quite some changes!

Used versions:

    "vite": "5.1.3",
    "vite-plugin-entry-shaking": "0.0.0-next-20240219224802",

Sadly, starting locally still results in an error:

Error: EISDIR: illegal operation on a directory, read
    at readFileSync (node:fs:453:20)
    at file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:210:14
    at async Context.measure (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:674:17)
    at async Object.doAnalyzeEntry (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:208:20)
    at async Object.analyzeEntry (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:195:10)
    at async file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:183:7
    at async Promise.all (index 0)
    at async file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:181:5
    at async Context.measure (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:674:17)
    at async Object.analyzeEntries (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:179:31) {
  errno: -21,
  code: 'EISDIR',
  syscall: 'read'
}
error when starting dev server:
Error: Could not analyze entry file "/<private>/ui/components/"
    at file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:199:11
    at async Object.analyzeEntry (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:195:10)
    at async file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:183:7
    at async Promise.all (index 0)
    at async file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:181:5
    at async Context.measure (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:674:17)
    at async Object.analyzeEntries (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:179:31)
    at async Context.init (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:663:20)
    at async configResolved (file:///<private>/node_modules/.pnpm/vite-plugin-entry-shaking@0.0.0-next-20240219224802_vite@5.1.3_vue@3.4.19/node_modules/vite-plugin-entry-shaking/dist/index.mjs:726:7)
    at async Promise.all (index 2)
 ELIFECYCLE  Command failed with exit code 1.

What I'm passing as config:

EntryShakingPlugin({
  targets: getAllLibs(),
  extensions: ["ts", "vue"],
}

Where getAllLibs returns a list of dirs that all contain a "index.ts" file.

commented

Well, I was indeed expecting some issues but not that early 😅

The error you mentioned leads to this line which didn't change between main and next branches, so that's kind of unexpected. Node's resolver should be able to resolve to an existing directory's index file but looking at the output caught error Error: Could not analyze entry file "/<private>/ui/components/", it seems like it doesn't.

Can you confirm that /ui/components/ directory actually contains an index.ts file (as opposed to an index.vue, which wouldn't work)? If it does, would you mind sharing your tsconfig/node version?

Yes, there is a /ui/components/index.ts.

.tsconfig

{
  "extends": "../../.tsconfig.base.json",
  "compilerOptions": {
    "baseUrl": "."
  },
  "include": [
    "**/*.ts",
    "**/*.vue"
  ],
  "exclude": [
    "node_modules"
  ]
}

And .tsconfig.base.json

{
  "compilerOptions": {
    "target": "es2020",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "resolveJsonModule": true,
    "noEmit": true,
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ],
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}

Node Version: v20.11.0

commented

I'm definitely having a hard time reproducing it, even by using your whole merged tsconfig and using the same node version. I've tried leaving trailing slashes at the end of entry paths, using aliases, mixed module extensions, etc. Tried on Linux and Windows environments.

Maybe there's something with your getAllLibs function? Is there any chance I could get a preview of its implementation? Anyway, I need to make a slight change to the fix I made for your #28 issue so I'll need to release another next tag for you to test it. If you have an idea of some kind of log that could help find the cause of your issue, please let me know!

Ok, I just wanted to debug the root cause, but installed a later version of Vite now:

    "vite": "5.1.4",
    "vite-plugin-entry-shaking": "0.0.0-next-20240219224802",

It works without any issues. It also feels way faster than the older versions 🤔

So, if you also think, we should not waste time investigating why it didn't work with the previous Vite version, I would be happy to just expect your next release 🙂

Do you already know roughly when the new release will be available?

commented

Next version's core has been ready for quite some time now but I initially really wanted to get the upcoming debugger on point before I release anything. But tbh, I won't ever be satisfied enough with it so II'll probably take two weeks to do some fine-tuning and eventually release it even if debugger's not 100% complete. I'd say most probably ~March 30th.

commented

@fdc-viktor-luft I've just released v0.4.0, I'm closing the issue but feel free to re-open if needed :-)