-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
error with esm on windows #98
Comments
I have to admit I have not tested that setup on Windows. |
C:\Users\amis\Desktop\fastify3-test\routes |
Unfortunately I do not know how to fix this. I'm moving this to fastify-autoload as a bug. I might need some help from a Windows users here.. maybe @StarpTech or @Ethan-Arrowood? |
The join from desm is doing this work? import { dirname } from 'path'; const __dirname = dirname(fileURLToPath(import.meta.url)); ... path.join(__dirname, 'public'))) ... |
yes, that's the idea |
I've actually tried that but still getting the same error. |
This seems the same as this one nodejs/node#31710 |
How can I help? Will |
@StarpTech my bad, I am making some test now and |
@StarpTech if you are a windows user just try to reproduce the issue using the provided |
I could fix it with fastify-autoloader/index.js if (type === 'module') {
content = await import(url.pathToFileURL(file).href)
} else {
content = require(file)
} app.js export function dirname(importMeta) {
return path.dirname(filename(importMeta));
}
export function filename(importMeta) {
return url.fileURLToPath(importMeta.url);
}
export default function (opts) {
const app = fastify(opts)
app.register(autoload, {
dir: path.join(dirname(import.meta), 'routes')
})
return app
} |
Nice, as supposed it worked! Now it would be nice to know why it was missing in the first place. Any clouds @mcollina ? |
I think that since fastify-plugin handles ESM natively the users doesn't have to use desm package. 🤔 |
Oh thanks |
No idea. The above code is exactly doing what desm is doing. See https://github.com/mcollina/desm/blob/master/index.js |
Can I steal @StarpTech code and send a PR? 😄 |
sure. I don't 100% understand the problem, but +1 |
@amis-shokoohi feel free 😄 |
why the heck this works on Mac and Linux then? :) |
Because in Linux a path is a valid file URL? 🤔 |
Released as v3.0.8! |
Indeed, I tried it with WSL2 on Windows and |
The Node.js parser takes c: part of the Windows paths as protocol. :/ |
@StarpTech can you open an issue on node core on this and tag me on it? Thanks. This is very confusing. |
I was following @mcollina tutorial for Fastify, and I faced with an error related to fastify-autoload plugin:
I'm running Node v14.7.0 on Windows 10.
This is how the app looks like:
app.js
/routes/hello.js
The text was updated successfully, but these errors were encountered: