Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

334
Views
Nodejs: use import in only one file

I have a project which is build using require, but now I need to use a package @nfteyez/sol-rayz, which only have support for ES6 import.

I cannot add type: module because there are lots of files.

I have tried changing file to mjs, but I get errors when importing it with require in another file.

I found in example that is possible when you enable module you can use import with:

// Define "require"
import { createRequire } from "module";
const require = createRequire(import.meta.url);

is there something similar for import? I am using node v17

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Go for dynamic import() function.

let solRayz = await import('@nfteyez/sol-rayz');

For complete suppression and use one common style, it is very difficult as the implicit packages have their own module system in their package files. For this particular problem, the following links might help

Complete flexibility of using module systems is not available as of now

What is the difference between .js and .mjs files?

https://nodejs.org/docs/latest/api/esm.html#esm_differences_between_es_modules_and_commonjs

https://www.geeksforgeeks.org/how-to-use-an-es6-import-in-node-js/

about 4 years ago · Juan Pablo Isaza Report

0

in node.js v14 and above, we can enable es module support by just add this in package.json

"type": "module"
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!