Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error reading config.js, must use import to load ES Module #1067

Closed
2 of 7 tasks
mdodge-ecgrow opened this issue Jul 7, 2021 · 7 comments
Closed
2 of 7 tasks

Error reading config.js, must use import to load ES Module #1067

mdodge-ecgrow opened this issue Jul 7, 2021 · 7 comments
Assignees

Comments

@mdodge-ecgrow
Copy link

mdodge-ecgrow commented Jul 7, 2021

Issue Creation Checklist

[x] I have read the contribution guidelines

Bug Description

When running the migration from the CLI ('npx sequelize-cli db:migrate'), I am getting the following error:

ERROR: Error reading "config\config.js". Error: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\...\config\config.js
require() of ES modules is not supported.
require() of C:\...\config\config.js from C:\Users\...\AppData\Roaming\npm-cache\_npx\13936\node_modules\sequelize-cli\lib\helpers\config-helper.js is an ES module file as it is a .js file whose nearest pare
nt package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\...\package.json.

I've tried renaming it to a .cjs file and I get even more errors. I can't remove the "type":"module" as I have my project fully set up to use that. So I would like to figure out the third option. "change the requiring code to use import()"

SSCCE

Here is the link to the SSCCE for this issue: LINK-HERE

This is my config.js file:

// You can delete this code block if you have included a link to your SSCCE above!

// import dotenv from 'dotenv';
// dotenv.config();

import 'dotenv/config.js';

const username = process.env.NAME;
const password = process.env.PASSWORD;
const database = process.env.DATABASE;
const host = process.env.HOST;
const port = process.env.DB_PORT;
const dialect = process.env.DIALECT;
const node_env = process.env.NODE_ENV;
const session_secret = process.env.SESSION_SECRET;
const base_url = process.env.BASE_URL;
const client_url = process.env.CLIENT_APP_LOC;
const secure_cookie = process.env.SECURE_COOKIE;

const config = {
	dev: {
		username,
		password,
		database,
		host,
		port,
		dialect,
		logging: true,
		session_secret,
		base_url,
		client_url,
		secure_cookie,
	},
	testing: {
		username,
		password,
		database,
		host,
		port,
		dialect,
		logging: true,
		session_secret,
		base_url,
		client_url,
		secure_cookie,
	},
	production: {
		username,
		password,
		database,
		host,
		port,
		dialect,
		logging: true,
		session_secret,
		base_url,
		client_url,
		secure_cookie,
	},
};

export default config[node_env];

What do you expect to happen?

I wanted it to correctly implement my migration and add in the new field.

What is actually happening?

I am getting the above error instead.

Output here

Additional context

Add any other context and details here.

Environment

  • Sequelize version: 6.6.2
  • Node.js version: 14.17.0
  • If TypeScript related: TypeScript version: XXX

Bug Report Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
@github-actions
Copy link

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Oct 27, 2021
@mariusa
Copy link

mariusa commented Oct 27, 2021

ping

@github-actions github-actions bot removed the stale label Oct 28, 2021
@github-actions
Copy link

github-actions bot commented Nov 4, 2021

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Nov 4, 2021
@mariusa
Copy link

mariusa commented Nov 4, 2021

@mattiamalonni @sdepold
7 days to close an issue is extremely aggressive, common... Especially as maintainers don't even look at these valid requests.

@github-actions github-actions bot removed the stale label Nov 5, 2021
@github-actions
Copy link

This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Nov 20, 2021
@mariusa
Copy link

mariusa commented Nov 20, 2021

.

@sdepold sdepold added type: bug and removed stale labels Nov 20, 2021
@sdepold sdepold self-assigned this Nov 20, 2021
@ephys ephys transferred this issue from sequelize/sequelize Apr 16, 2022
@ephys
Copy link
Member

ephys commented Apr 16, 2022

I believe this was fixed by #987

@ephys ephys closed this as completed Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants