samonxian / vite-plugin-build

Vite library mode plugin,which support transfom the whole folder and emit dceclaration files. Vite 库模式插件,支持整个文件夹的转换和声明文件生成。(支持 vanilla、react、vue3 和 svelte)
60 stars 6 forks source link

Build error 'The "path" argument must be of type string. Received undefined' when using Vite 3.2.0++ #5

Closed mddanish00 closed 1 year ago

mddanish00 commented 1 year ago

Full error message

The "path" argument must be of type string. Received undefined
error during build:
TypeError [PLUGIN_ERROR]: The "path" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:387:5)
    at validateString (node:internal/validators:162:11)
    at Object.resolve (node:path:167:9)
    at resolve (file:///F:/Workspace/GithubForks/vite-plugin-build-react-ts-bphvr/node_modules/vite/dist/node/chunks/dep-c842e491.js:46432:35)
    at file:///F:/Workspace/GithubForks/vite-plugin-build-react-ts-bphvr/node_modules/vite/dist/node/chunks/dep-c842e491.js:46545:60
    at Array.map (<anonymous>)
    at doBuild (file:///F:/Workspace/GithubForks/vite-plugin-build-react-ts-bphvr/node_modules/vite/dist/node/chunks/dep-c842e491.js:46545:43)
    at async Module.build (file:///F:/Workspace/GithubForks/vite-plugin-build-react-ts-bphvr/node_modules/vite/dist/node/chunks/dep-c842e491.js:46416:16)
    at async lastBuild (F:\Workspace\GithubForks\vite-plugin-build-react-ts-bphvr\node_modules\vite-plugin-build\lib\buildFiles.js:111:20)
    at async Promise.all (index 0)

Can be easily reproduced using react-ts example. I only upgrade both Vite (v3.2.2) and vite-plugin-build (v0.6.0) to the latest version.

From my testing with my own repo, the error starts on Vite v3.2.0. It is okay on v3.1.8 and below.

maxsolovev commented 1 year ago

Same problem

agileago commented 1 year ago

+1

FireTable commented 1 year ago

+1

bisubus commented 1 year ago

It looks more like Vite bug, but there also may be incompatibility problem with the plugin.

Debugged it to this place

build contains default values for some reason that cannot be overridden from user config at this point and so it's not possible to fix this on user side.

Here it becomes possible for outputs array to contain entries without dir

And here they fail to resolve.

Related: https://github.com/vitejs/vite/issues/6929

I can confirm that downgrading to Vite 3.1 helps.

samonxian commented 1 year ago

It is because of the code below which is not compatible width multiple rollupOptions outputs setting (output[].dir is undefined).

const outDirs = normalizedOutputs.map(({ dir }) => resolve(dir!))

If i set the output[].dir, it will throw below

Invalid value for option "output.dir" - you must set either "output.file" for a single-file build or "output.dir" when generating multiple chunks.

I haven't find a way to deal with it, maybe you should use Vite below 3.2.0.

samonxian commented 1 year ago

v0.7.0 fixed! @Miracutor