I am trying to convert my npm package imports from ES5 (require) to ES6 (import...from) but I keep getting unexpected identifier errors. What should I be looking out for?
I have read through forums but honestly not sure what to try. I checked the documentation in MDN but none of those worked. Every single package has been tried individually but none of them work.
// changed version
import fs from 'fs';
// old imports
// const fs = require('fs')
Because they're NPM modules - IIRC you have to use require
for those.
I think you can change the command you use slightly and it should work if your Node version is high enough. You'll also need to change the file type from .js
to .mjs
(module JS):
node --experimental-modules moduleApp.mjs
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments