donnikitos / vite-plugin-php

Vite's speed and tooling to preprocess PHP-files!
https://www.npmjs.com/package/vite-plugin-php
MIT License
40 stars 0 forks source link

Any errors that occur during the build process get swallowed and then surfaced as "no such file or directory" #14

Closed charleskilbourne closed 3 months ago

charleskilbourne commented 7 months ago

The actual error here was bad config I wrote in another plugin, but it surfaced as this. This has happened with other errors as well. I am developing on windows

error during build:
Error: ENOENT: no such file or directory, open 'template/.php-tmp/page-manage.php.html'
    at Object.openSync (node:fs:603:3)
    at Object.readFileSync (node:fs:471:35)
    at unescapePHP ([NODE_MODULES_PATH]\vite-plugin-php\dist\index.cjs:52:28)
    at [NODE_MODULES_PATH]\vite-plugin-php\dist\index.cjs:6979:24
    at Array.forEach (<anonymous>)
    at Object.closeBundle ([NODE_MODULES_PATH]\vite-plugin-php\dist\index.cjs:6978:17)
    at file:///[NODE_MODULES_PATH]/rollup/dist/es/shared/node-entry.js:19611:40
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
    at async PluginDriver.hookParallel (file:///[NODE_MODULES_PATH]/rollup/dist/es/shared/node-entry.js:19539:9)
donnikitos commented 7 months ago

Interesting, first try to remove the /.php-tmp directory and start the build process again. Otherwise I would be really glad if you could create a step-by-step guide to reproduce the error.

kareiva commented 5 months ago

I am experiencing same error.

Here is my sample repository: https://github.com/kareiva/LYFD/tree/vite-php

I have an index.php that references few JS files, one CSS and that's it. during vite build it throws me the same error.

@donnikitos any chance you could try doing a build on the above repo?

kareiva commented 5 months ago

OK I was too fast to post - I've figured out that my build actually passes - I had leftover modules copied from the dist/ version.

Here is my fix: https://github.com/kareiva/LYFD/commit/e8760cdd00dea86e0d5567114922d076f94f0d8a

donnikitos commented 5 months ago

Oh, so the problem was, that the modules were missing? A proper error message would be nice to have then...

donnikitos commented 5 months ago

If you have troubles you can check out the Starter-Repo.

NicolasReibnitz commented 4 months ago

@donnikitos I think you might be missing the point here, but I can absolutely see how this isn't very clear.

I just encountered the same problem when integrating Vue support into the starter-repo. I also made a mistake and figured out how to fix it. But that's not important. The problem is that the error message that would have pointed my mistake out very clearly was replaced by a confusing error message that is similar to the one mentioned at the start:

error during build:
[build-php] ENOENT: no such file or directory, open 'dist/.php-tmp/pages/about.php.html'
    at Object.openSync (node:fs:596:3)
    at readFileSync (node:fs:464:35)
    at unescapePHP ([...]/vite-plugin-php/dist/index.mjs:39:17)
    at [...]/vite-plugin-php/dist/index.mjs:6990:24
    at Array.forEach (<anonymous>)
    at Object.closeBundle ([...]/vite-plugin-php/dist/index.mjs:6989:17)
    at [...]/rollup/dist/es/shared/node-entry.js:19743:40
    at async Promise.all (index 0)
    at async PluginDriver.hookParallel ([...]/rollup/dist/es/shared/node-entry.js:19671:9)
    at async [...]/rollup/dist/es/shared/node-entry.js:20588:13

As I assumed that I had made a mistake with my configuration or had a compatibility issue, I tried everything I could think of. Finally, I temporarily removed the whole vite-plugin-php part. That's when the actual error was visible:

[vite]: Rollup failed to resolve import "/vite.svg" from "[...]/php-vite-starter-vue-ts/src/vue/App.vue?vue&type=script&setup=true&lang.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at viteWarn ([...]/vite/dist/node/chunks/dep-CzJTQ5q7.js:65881:17)
    at onRollupWarning ([...]/vite/dist/node/chunks/dep-CzJTQ5q7.js:65916:5)
    at onwarn ([...]/vite/dist/node/chunks/dep-CzJTQ5q7.js:65576:7)
    at [...]/rollup/dist/es/shared/node-entry.js:18483:13
    at Object.logger [as onLog] ([...]/rollup/dist/es/shared/node-entry.js:20131:9)
    at ModuleLoader.handleInvalidResolvedId ([...]/rollup/dist/es/shared/node-entry.js:19073:26)
    at [...]/rollup/dist/es/shared/node-entry.js:19031:26

The problem was that I couldn't import a file from the public folder as usual. But again, that's not the point. The error was replaced by the misleading error about ./dist/.php-temp/... not being found.

So I'm afraid that whenever I get an error about ./dist/.php-temp/..., I'll have to disable the whole PHP part, use an index.html file instead, and build again just to see the actual error message.

I couldn't begin to think of why this should happen or if that's a vite problem rather than a problem with your plugin. But it's a bit of a problem.

Oh, and I'm on macOS, so Windows is not the issue here.

Please let me know if you need more information or how I can help.

Cheers and thanks!

donnikitos commented 4 months ago

Ah okay, now I understand, what you guys mean with "errors being swallowed". That might be a little tricky to fix since the plugin captures and overrides the default file entry point (index.html). At least I understand, what is happening now - Thank you for the detailed bug description!

But, never the less I will get on it!