Closed aravindhnivas closed 1 year ago
interesting...can you share your code or way you used the package ?
i just create a live demo and i didn't get the same error, so it will be helpful if you share how did you step up it in your project.
I have installed the package and imported it in vite.config.js
as import Components from 'unplugin-svelte-components/vite
.
It ended up in this error, and when I checked the dist/vite.js
file in the unplugin-svelte-components
package the first two line has hardcoded information
import { createRequire as topLevelCreateRequire } from 'module';
const require = topLevelCreateRequire("file:///home/mohamed/Desktop/projects/svelte/unplugin-svelte-components/tsup.config.ts");
And I am using just svelte (not sveltekit) for my project.
update to the latest version, demo
Sorry, I updated to the latest version
"svelte": "^3.54.0",
"vite": "^4.0.0"
"unplugin-svelte-components": "^0.2.1",
But received the following error
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
at new NodeError (node:internal/errors:387:5)
at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1075:11)
at defaultResolve (node:internal/modules/esm/resolve:1155:3)
at nextResolve (node:internal/modules/esm/loader:173:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:852:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:439:18)
at ESMLoader.import (node:internal/modules/esm/loader:536:22)
at importModuleDynamically (node:internal/modules/esm/translators:110:35)
at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
at configResolved (file:///D:/github_projects/felion_gui_v4/node_modules/unplugin-svelte-components/dist/chunk-EZRYSAWV.mjs:25651:21)
this fixed it though
changing configfile to URL using pathToFileURL
const configFile = path.join(config.root, "./svelte.config.js")
const pkg = await import(configFile)
to
import { pathToFileURL } from 'url'
...
const configFile = path.join(config.root, "./svelte.config.js")
const pkg = await import(pathToFileURL(configFile ))
what version of node are you using ?
Node version ^18
this fixed it though
changing configfile to URL using
pathToFileURL
const configFile = path.join(config.root, "./svelte.config.js") const pkg = await import(configFile)
to
import { pathToFileURL } from 'url' ... const configFile = path.join(config.root, "./svelte.config.js") const pkg = await import(pathToFileURL(configFile ))
the problem with the pathToFileURL
is breaking in Linux, i think you are using windows, right ?
DTS Build start
src/core/unplugin.ts(45,30): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'URL'.
Error: error occured in dts build
at Worker.<anonymous> (/home/mohamed/Desktop/projects/svelte/unplugin-svelte-components/node_modules/.pnpm/tsup@6.2.3_typescript@4.8.4/node_modules/tsup/dist/index.js:2157:26)
at Worker.emit (node:events:513:28)
at MessagePort.<anonymous> (node:internal/worker:233:53)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:731:20)
at exports.emitMessage (node:internal/per_context/messageport:23:28)
Error: Failed to compile. Check the logs above.
at error (/home/mohamed/Desktop/projects/svelte/unplugin-svelte-components/node_modules/.pnpm/rollup@2.79.1/node_modules/rollup/dist/shared/rollup.js:198:30)
at throwPluginError (/home/mohamed/Desktop/projects/svelte/unplugin-svelte-components/node_modules/.pnpm/rollup@2.79.1/node_modules/rollup/dist/shared/rollup.js:21718:12)
at Object.error (/home/mohamed/Desktop/projects/svelte/unplugin-svelte-components/node_modules/.pnpm/rollup@2.79.1/node_modules/rollup/dist/shared/rollup.js:22672:20)
at Object.error (/home/mohamed/Desktop/projects/svelte/unplugin-svelte-components/node_modules/.pnpm/rollup@2.79.1/node_modules/rollup/dist/shared/rollup.js:21895:42)
at Object.transform (/home/mohamed/Desktop/projects/svelte/unplugin-svelte-components/node_modules/.pnpm/tsup@6.2.3_typescript@4.8.4/node_modules/tsup/dist/rollup.js:7217:20)
at /home/mohamed/Desktop/projects/svelte/unplugin-svelte-components/node_modules/.pnpm/rollup@2.79.1/node_modules/rollup/dist/shared/rollup.js:22879:40
DTS Build error
i will try to find work around
Yes I'm using windows. I checked some other repos issues, in general, looks like only windows have this issue.
did the other repos resolved this issue ?
it was discussed here https://github.com/okonet/lint-staged/issues/1054#issue-1059422989
Since URL type is the issue in Linux, can the following method work?
const pkg = await import(pathToFileURL(configFile).toString());
i just released new version, please check it.
Great, thanks it is working.
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received 'file:///home/mohamed/Desktop/projects/svelte/unplugin-svelte-components/tsup.config.ts'