Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom drivers failed on build #2096

Closed
tchiotludo opened this issue Jun 8, 2023 · 5 comments · Fixed by #2193
Closed

Custom drivers failed on build #2096

tchiotludo opened this issue Jun 8, 2023 · 5 comments · Fixed by #2193

Comments

@tchiotludo
Copy link

Environment


  • Operating System: Linux
  • Node Version: v18.13.0
  • Nuxt Version: 3.5.2
  • Nitro Version: 2.4.1
  • Package Manager: npm@9.2.0
  • Builder: vite
  • User Config: modules, app, css, content, router, devServer, vue, gtag, runtimeConfig, nitro, routeRules, build, multiCache
  • Runtime Modules: @nuxt/devtools@0.5.5, @nuxt/content@2.6.0, nuxt-gtag@0.5.7, nuxt-simple-sitemap@2.6.1, nuxt-multi-cache@3.0.1
  • Build Modules: -

Reproduction

The full source is here

Describe the bug

Hey,

I've an issue, I'm trying to implement a custom drivers.
Everything work fine on development but npm run build failed this error:

Cannot read properties of undefined (reading 'getKeys')

diging the stacktrace, here is the orginal error from here

require() of ES Module /home/ludo/Web/kestra/kestra.io/drivers/apidocs/driver.mjs not supported.                         
Instead change the require of /home/ludo/Web/kestra/kestra.io/drivers/apidocs/driver.mjs to a dynamic import() which is available in all CommonJS modules.

Additional context

No response

Logs

No response

@SwenVogel
Copy link

I have the same problem with a custom driver:

` ERROR Couldn't load driver /Users/vogel/Entwicklung/Workspace/ypsystems/brock/rcp-ui-web/src/drivers/payload/driver.mjs 12:08:44

ERROR Cannot read properties of undefined (reading 'getKeys') `

and using the following nuxt.config:

`
...

sources: [
"content",
{
driver: resolve("src", "drivers", "payload", "driver.mjs"),
name: "payload",
prefix: "/payload",
....
`

Does anybody know to resolve this issue?

@shareable-vision
Copy link
Contributor

I am getting the same error while building with custom webdav driver:

Couldn't load driver .../web.nuxt/server/drivers/webdav.mjs

@shareable-vision
Copy link
Contributor

shareable-vision commented Jul 24, 2023

We need to modify the getMountDriver() in utils.ts.

export function getMountDriver (mount: MountOptions) {
  const dirverName = mount.driver as keyof typeof unstorageDrivers
  if (unstorageDrivers[dirverName]) {
    return unstorageDrivers[dirverName](mount as any)
  }

  try {
    // eslint-disable-next-line @typescript-eslint/no-var-requires
    return require(mount.driver).default(mount as any)
  } catch (e) {
    // eslint-disable-next-line no-console
    console.error("Couldn't load driver", mount.driver)
  }
}

We need to make getMountDriver() async and "change the require of . . . to a dynamic import()":

async function getMountDriver(mount) {
  const dirverName = mount.driver;
  if (unstorageDrivers[dirverName]) {
    return unstorageDrivers[dirverName](mount);
  }
  try {
    return (await import(mount.driver)).default(mount) //require(mount.driver).default(mount);
  } catch (e) {
    console.error("Couldn't load driver", mount.driver);
  }
}

And await the function at this block of the async setup():

 for (const [key, source] of Object.entries(sources)) {
    storage.mount(key, await getMountDriver(source));
 }

@shareable-vision
Copy link
Contributor

Also it appears to be necessary to add to tsconfig.json:

"compilerOptions": {
  "lib": [ "es2015" ]
},

to avoid Typescript error An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option.

@shareable-vision
Copy link
Contributor

Submitted PR to resolve issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants