Open mcremer-able opened 1 year ago
I'm having the same problem but bigger because I wrote my driver in typescript and can't even use the workaround because it only gets bundled into the server and is not importable
I had a look in the code and it is definitely more complicated than just adding the pure driver factory to the type definition because they use the string to generate the variable name and use dynamic imports
I am facing the same problem trying to use a Custom Driver. Any updates on that issue?
I have the same problem. Does nitro support Custom Driver?
You should use an absolute path for your custom driver location :
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
export default defineNitroConfig({
storage: {
"custom-db": {
driver: resolve(
dirname(fileURLToPath(import.meta.url)),
"unstorage/custom-driver.ts"
),
},
},
});
You should use an absolute path for your custom driver location :
import { resolve, dirname } from "node:path"; import { fileURLToPath } from "node:url"; export default defineNitroConfig({ storage: { "custom-db": { driver: resolve( dirname(fileURLToPath(import.meta.url)), "unstorage/custom-driver.ts" ), }, }, });
It worked for me. But I think we should support using Driver
/Storage
imported from other ts/js files directly. Since this didn't support TypeScript files and is not very elegant.
I would like to help if we have a plan to support this.
It supports typescript files. You can replace dirname(fileURLToPath(import.meta.url))
with __dirname
if you want something less verbose.
Environment
nitropack@0.4.24 $ node --version v16.17.0
Reproduction
Follow the example of unstorage https://github.com/unjs/unstorage#making-custom-drivers I used the original memory driver as "custom driver"
Describe the bug
The current interface for storage options is:
but unstorage allows the use of custom drivers and we are not using them.
Additional context
I found https://github.com/unjs/nitro/blob/main/src/rollup/plugins/storage.ts on line 47
${driverImports.map(i => genImport(i, genSafeVariableName(i))).join('\n')}
I am not quite sure if that means we should do the followingThis kind of complex and error prone We should allow the user to pass in the driver directly and just
driver:new Driver({})
Logs
No response