I’m working on a strapi.io plugin (typescript) and I would like to use the node package file-type.
import {fileTypeFromBuffer} from “file-type”;
My plugin compiles just fine. But strapi does not start.
I get:
…/strapi-server.js: require() of ES Module …/node_modules/file-type/index.js from …myjsfile.js not supported.
Instead change the require of index.js in …myjsfile.js to a dynamic import() which is available in all CommonJS modules.
I’m not sure if I can change anything since my code runs as a plugin in strapi. And I have no desire to change the strapi code.
Has anyone solved the module loading problem ?
Regards
I have also some difficulties to integrate p-queue which is now an ES Module. I would like to use it into a plugin service. I try to use a dynamic import to solve this kind of issue but it does not work. Do I miss something ?
return {
async init() {
console.log(‘Init Julius GPT Queue Service ’);
// Dynamically import p-queue
const PQueue = (await import(‘p-queue’)).default;
queue = new PQueue({ concurrency: 2 });
},
async addTaskToQueue(topic: string) {
if (!queue) {
throw new Error("Queue has not been initialized.");
}
// Add a new job to the queue
await queue.add(() => this.handleTask(topic));
},
async handleTask(topic: string) {
console.log(`Processing task: ${topic}`);
await new Promise(resolve => setTimeout(resolve, 10000));
console.log(`Finished processing task: ${topic}`);
},