Skip to content

v6: Improve support for ESM & CJS config files #990

Open

Description

@ephys

We currently search for config/config.json and config/config.js

We should also automatically look for extensions .cjs, and .mjs so specifying the config file location is not necessary.


We should do the same for .sequelizerc (https://github.com/sequelize/cli/blob/main/src/core/yargs.js#L7): load it using importHelper and support files: .sequelizerc (as js), .sequelizerc.js, .sequelizerc.cjs, .sequelizerc.mjs, .sequelizerc.json.

Activity

  1. WikiRik commented on Jan 13, 2022

    @WikiRik
    Member

    Second part would fix #951, correct?

  2. ephys commented on Jan 13, 2022

    @ephys
    MemberAuthor

    yes :)

    I've started working on a PR. Also this would be much easier if we had top-level-await

  3. WikiRik commented on Jan 13, 2022

    @WikiRik
    Member

    So to consolidate this with the other feature request; we also need to include a YML to JSON parser (or something equivalent) so we can also accept .yml and .yaml files.
    And for completeness; there is no demand currently to check if the file without extension is a YAML file so that's not in scope for this feature request

    Having it in the package.json directly or passable through the command line is still part of #951 since that requires a different approach probably

  4. ephys commented on Jan 13, 2022

    @ephys
    MemberAuthor

    If we're going to support YML & package.json as well, we could use https://github.com/davidtheclark/cosmiconfig. But they don't support ESM yet.

    CLI options would be a separate feature yes.

  5. mariusa commented on May 9, 2022

    @mariusa

    This PR #987
    includes docs update which says
    ESM configuration files are supported for Node versions that support ESM natively, either via passing `--config config/config.mjs`, or by setting the `type` to `module` in your `package.json`.

    In a project using "type": "module",, newly generated migration files are still non ESM:

    npx sequelize-cli migration:create --name test1
    

    generates

    'use strict'
    
    module.exports = {
        async up(queryInterface, Sequelize) {
            /**
             * Add altering commands here.
             *
             * Example:
             * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
             */
        },
    
        async down(queryInterface, Sequelize) {
            /**
             * Add reverting commands here.
             *
             * Example:
             * await queryInterface.dropTable('users');
             */
        }
    }
    
  6. ephys commented on May 13, 2022

    @ephys
    MemberAuthor

    Similarly to #960, we could detect the module type in package.json, and provide a --module cjs|esm option, and generate the right contents accordingly

  7. agjs commented on Jan 20, 2023

    @agjs

    @ephys Is there any movement on this :-)? I've just spent an hour or two and still dealing with issues. Should I continue with trying to fix it on my end, or did you guys end up providing a support for mjs?

    Thanks a lot

  8. WikiRik commented on Jan 20, 2023

    @WikiRik
    Member

    Our efforts are currently focused on getting the first beta version out for sequelize v7. After that we will start looking into updating the CLI but no promises on a timeline yet

    But if you open a PR we will make the time to review it

  9. IvanGarzon commented on May 16, 2023

    @IvanGarzon

    @WikiRik is there any kind of improving to support ESM for running migration using .sequelizerc configuration yet? I thought that migrating to sequelize 7 this is issue would it be fixed but I am still having same issues to not be able to run migrations and seeders written in ESM :(

  10. mahnunchik commented on Oct 19, 2023

    @mahnunchik

    Any news?

  11. nbkhope commented on Nov 23, 2024

    @nbkhope

    Can we switch to using ESM import/export for .sequelizerc yet, v >= 6?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions