Description
I'm testing projects renaming js to .mjs in order to execute them with --experimental-modules
they are proyects running ok with babel.
But I keep guessing where the error can be found on my code. I get always an error that it's hard to find:
(node:16709) ExperimentalWarning: The ESM module loader is experimental.
SyntaxError: Invalid or unexpected token
at ModuleJob.loaders.set [as moduleProvider] (internal/loader/ModuleRequest.js:32:13)
at
by example I can copy this example code where the error is produced, but it's not only with this situation but in anothers too. Why Node don't give me the line and the code that produces the error ? maybe it's better I try with node 9 ? that version is more compatible with --experimental-modules ?
Example code:
test.js
import { pgClient } from '../connection.mjs';
//or
//import { pgClient } from '../connection';
const pool = pgClient();
(async function(){
const client = await pool.connect();
const res = await client.query('
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public');
console.log( JSON.stringify(res.rows[0]));
client.release();
})();
await pool.end();
connection.jms (this file have errors , by example using require() or anothers, but the idea is to get display errors that help you to find errors )
import dotenv from 'dotenv';
dotenv.config();
import Sequelize from 'sequelize';
//import { Pool, Client } from 'pg';
export const db = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASS, {
host: 'localhost',
port: '5432',
dialect: 'postgres',
timezone: '+00:00',
pool: {
max: 5,
min: 0,
idle: 10000
},
});
// conection segurisé direct verst postresql without graphl, example dont' expose password for users
export const pgClient = () => {
const { Pool, Client } = require('pg');
const pool = new Pool()
return pool;
};
I execute with:
node --experimental-modules ./src/test.mjs
again I repeat the error message:
(node:17571) ExperimentalWarning: The ESM module loader is experimental.
SyntaxError: Invalid or unexpected token
at ModuleJob.loaders.set [as moduleProvider] (internal/loader/ModuleRequest.js:32:13)
at <anonymous>
Version: 8.9.1
Platform: Mac ElCapitan