fastify / fastify-plugin

Plugin helper for Fastify
MIT License
199 stars 43 forks source link

`fastify not found, proceeding anyway` if running ES module Node.js program #101

Closed coreyfarrell closed 4 years ago

coreyfarrell commented 4 years ago

💥 Regression Report

Loading plugins which use fastify-plugin produces a warning message when running a native ES module program.

Last working version

Worked up to version: 2.0.2

Stopped working in version: 2.0.3

To Reproduce

Steps to reproduce the behavior:

Install latest fastify and fastify-static, run the following script.mjs (tested in Node.js 14.8.0):

// script.mjs
import fastifyStatic from 'fastify-static';

Expected behavior

fastify-static should validate the expected version of fastify is installed, nothing should display. Instead it prints:

fastify not found, proceeding anyway

Adding a printout of the exception shows TypeError: Cannot read property 'filename' of undefined.

Your Environment

Eomm commented 4 years ago

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

fox1t commented 4 years ago

I've just tested this and I am not able to reproduce it. Can you provide a full repro repo?

fox1t commented 4 years ago

I had to use this in order to set the root folder for fastify-static:

fastify.register(fastifyStatic, {
  root: join(dirname(fileURLToPath(import.meta.url)), "static"),
});
fox1t commented 4 years ago

Ok I found the line that throws in ESM contexts: https://github.com/fastify/fastify-plugin/blob/master/plugin.js#L89