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
System Information
-
Strapi Version: 4.6.2
-
Operating System: Mac
-
Database: psql
-
Node Version: 18
-
NPM Version:
-
Yarn Version: 1.2
Bump - any solutions to this?
Hello,
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 ?
import { Strapi } from ‘@strapi/strapi’;
export default ({ strapi }: { strapi: Strapi }) => {
let queue: any;
return {
async init() {
console.log(‘Init Julius GPT Queue Service ![:rocket: :rocket:](https://forum.strapi.io/images/emoji/twitter/rocket.png?v=12)
![:rocket: :rocket:](https://forum.strapi.io/images/emoji/twitter/rocket.png?v=12)
![:rocket: :rocket:](https://forum.strapi.io/images/emoji/twitter/rocket.png?v=12)
![:rocket: :rocket:](https://forum.strapi.io/images/emoji/twitter/rocket.png?v=12)
![:rocket: :rocket:](https://forum.strapi.io/images/emoji/twitter/rocket.png?v=12)
![:rocket: :rocket:](https://forum.strapi.io/images/emoji/twitter/rocket.png?v=12)
’);
// 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}`);
},
};
};
Thanks,
Christophe
I have the same problem, I want to use file-type in my custom plugin, any solutions?