nWidart / laravel-modules

Module Management In Laravel
https://docs.laravelmodules.com
MIT License
5.5k stars 954 forks source link

vite-module-loader.js not working on windows os #1867

Open Riemi001 opened 3 months ago

Riemi001 commented 3 months ago

vite-module-loader.js cant finde Modules. I add console.error(error); in this code to get the full error `

    try {
      await fs.access(viteConfigPath);
      // Import the module-specific Vite configuration
      const moduleConfig = await import(viteConfigPath);

      if (moduleConfig.paths && Array.isArray(moduleConfig.paths)) {
        paths.push(...moduleConfig.paths);
      }
    } catch (error) {
        console.error(error);
      // vite.config.js does not exist, skip this module
    }`

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:239:11)
at defaultLoad (node:internal/modules/esm/load:130:3)
at ModuleLoader.load (node:internal/modules/esm/loader:396:13)
at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:56)
at new ModuleJob (node:internal/modules/esm/module_job:67:26)
at #createModuleJob (node:internal/modules/esm/loader:290:17)
at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:247:34)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:17)
at async ModuleLoader.import (node:internal/modules/esm/loader:315:23) {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

Riemi001 commented 3 months ago

I have a working solution

add import { pathToFileURL } from 'url'

and change the code to

const moduleConfig = await import(pathToFileURL(viteConfigPath).toString());

abbasmashaddy72 commented 3 months ago

Same issue on Linux also

When Checking for Error, it returns:

vite.config.js not found for module CMS, skipping... ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/abbasmashaddy72/Documents/Project Sites/Clients/final-saas/Modules/CMS/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/abbasmashaddy72/Documents/Project%20Sites/Clients/final-saas/Modules/CMS/vite.config.js:15:17
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
    at async collectModuleAssetsPaths (file:///home/abbasmashaddy72/Documents/Project%20Sites/Clients/final-saas/vite.config.js.timestamp-1719485724773-754d8d24ece3c.mjs:31:32)
    at async getConfig (file:///home/abbasmashaddy72/Documents/Project%20Sites/Clients/final-saas/vite.config.js.timestamp-1719485724773-754d8d24ece3c.mjs:60:20)
    at async loadConfigFromFile (file:///home/abbasmashaddy72/Documents/Project%20Sites/Clients/final-saas/node_modules/vite/dist/node/chunks/dep-BcXSligG.js:66754:24)
    at async resolveConfig (file:///home/abbasmashaddy72/Documents/Project%20Sites/Clients/final-saas/node_modules/vite/dist/node/chunks/dep-BcXSligG.js:66364:24)
    at async build (file:///home/abbasmashaddy72/Documents/Project%20Sites/Clients/final-saas/node_modules/vite/dist/node/chunks/dep-BcXSligG.js:65459:18)
    at async CAC.<anonymous> (file:///home/abbasmashaddy72/Documents/Project%20Sites/Clients/final-saas/node_modules/vite/dist/node/cli.js:828:5)