You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
##Issue Description
When adding the plugin to a typescript Fastify project, I received a module import error on server start. The project was compiling to ES2022 (modules) and not CommonJs.
file-transfer-automation/node_modules/fastify-bree/lib/mjs/index.js:1
import FastifyPlugin from 'fastify-plugin';
^^^^^^
SyntaxError: Cannot use import statement outside a module
The issue is caused by a number of small issues:
There is nothing to identify the files in the mjs directory as modules.
The following issues related to this block in lib\index.ts
import BreeClass, { BreeOptions } from 'bree'
import { FastifyPluginAsync } from 'fastify'
import FastifyPlugin from 'fastify-plugin'
import * as fs from 'fs'
import { BreeTS } from './plugin'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Bree = require('bree')
Mixing import and require against Bree (modules can't use require)
Modules require the .js extension on imports which is missing from the BreeTS plugin.4.
This lead me to a great blog post which all but handed the solution to me.
Having read it, I was writing a pull request but ran in to an issue where fixing MJS breaks it for ts-node. Correcting item 3 breaks ts-node tests unless compilation has been done as adding the extension makes a reference to a "non existent file" in ts-node. There is a heated discussion on the Typescript GitHub that you might be aware of where extension rewrites are completely ruled out despite modules requiring the .js extension.
This has all lead me to rework my project to CommonJs as ESM/TS is just filled with complication. Looking at 4.9 there is a bit about supporting .ts as an extension for modules like other run times do, though reading through I can't be confident compilation will replace .ts with .js like is needed in this instance.
The only thing that crossed my mind was splitting that Bree TS plugin out in to it's own NPM module and bringing it in to this package as a dependency.
The text was updated successfully, but these errors were encountered:
##Issue Description
When adding the plugin to a typescript Fastify project, I received a module import error on server start. The project was compiling to ES2022 (modules) and not CommonJs.
The issue is caused by a number of small issues:
The following issues related to this block in
lib\index.ts
This lead me to a great blog post which all but handed the solution to me.
Having read it, I was writing a pull request but ran in to an issue where fixing MJS breaks it for ts-node. Correcting item 3 breaks ts-node tests unless compilation has been done as adding the extension makes a reference to a "non existent file" in ts-node. There is a heated discussion on the Typescript GitHub that you might be aware of where extension rewrites are completely ruled out despite modules requiring the .js extension.
This has all lead me to rework my project to CommonJs as ESM/TS is just filled with complication. Looking at 4.9 there is a bit about supporting .ts as an extension for modules like other run times do, though reading through I can't be confident compilation will replace .ts with .js like is needed in this instance.
The only thing that crossed my mind was splitting that Bree TS plugin out in to it's own NPM module and bringing it in to this package as a dependency.
The text was updated successfully, but these errors were encountered: