Import external module in plugin

System Information
  • Strapi Version: 4.3.2
  • Node Version: 16.15.1
  • NPM Version: 8.11.0

Hey,
I want to import a module from a file.ts from utils folder to use it in my services server in a strapi plugin.
image

But when i import it with "const module = require(’…/…/…/…/utils/myFile’), i get a error that say :
"error : Could not load js config file …/myPlugins/strapi-server.js : Cannot find module ‘…/…/…/…/utils/myFile’)

Someone has an idea how my module can be accessible to my services ?

Thanks !

If you use Typescript, you probably need to use this format for imports:

import module from …/…/…/…/utils/myFile''; // If a default export exists
import * as module from …/…/…/…/utils/myFile''; // If no default export

I can’t use this format import because my plugin is in JS.
I got a import format error : ‘Cannot use import statement outside a module’
That’s why i use the require format for imports, but he can’t find my module.

how did you export the module in your myfile.js ?