Skip to content

Can't resolve 'pg-hstore' #7509

Closed
Closed

Description

@dlimkin

May be necessary need move 'pg-hstore' with devDependencies in dependencies?

ERROR in ./~/sequelize/lib/dialects/postgres/hstore.js
Module not found: Error: Can't resolve 'pg-hstore' in 'node_modules/sequelize/lib/dialects/postgres'
 @ ./~/sequelize/lib/dialects/postgres/hstore.js 3:15-35
 @ ./~/sequelize/lib/dialects/postgres/data-types.js
 @ ./~/sequelize/lib/data-types.js
 @ ./~/sequelize/lib/sequelize.js
 @ ./~/sequelize/index.js

Dialect: any
Sequelize version: 4.0.0-2

Activity

  1. janmeier commented on Apr 12, 2017

    @janmeier
    Member

    pg-hstore is only installed in dev (when you run npm install directly in the sequelize directory) - In which case are you seeing this?

  2. dlimkin commented on Apr 24, 2017

    @dlimkin
    Author

    When I build my project with webpack.

  3. janmeier commented on Apr 25, 2017

    @janmeier
    Member
  4. rozzzly commented on May 21, 2017

    @rozzzly

    This needs to be reopened, This is an issue with how sequelize conditionally requires its dependencies. If I can't just yarn add sequelize and have it work then it's a problem on your end. I'm using mysql, not postgress so ideally the code that attempts require('pg-hstore') should never had ran. I didn't use to have this issue so its due to a regression.

  5. alucic commented on Jun 19, 2017

    @alucic

    @janmeier Can you reopen this issue?
    It is impossible to bundle up code using webpack without installing all dependencies that are required.

    Why are you trying to webpack sequelize at all - its a backend library?
    #6142 (comment)

    Were deploying single bundled up file to the production servers and here all data types are being required which breaks our build since not all of the required dependencies are installed
    https://github.com/sequelize/sequelize/blob/v4.1.0/lib/data-types.js#L842-L845

  6. janmeier commented on Jun 20, 2017

    @janmeier
    Member

    This needs to be reopened, This is an issue with how sequelize conditionally requires its dependencies. If I can't just yarn add sequelize and have it work then it's a problem on your end. I'm using mysql, not postgress so ideally the code that attempts require('pg-hstore') should never had ran. I didn't use to have this issue so its due to a regression.

    Hstore is only loaded, if you actually use it.

    hstore = require('./hstore');

    @janmeier Can you reopen this issue?
    It is impossible to bundle up code using webpack without installing all dependencies that are required.

    I'm sure webpack can be configured to ignore some modules, but that is outside the scope of sequelize

  7. stunningpixels commented on Aug 8, 2017

    @stunningpixels

    Even though i'm using Postgres as my dialect, it doesn't seem like Tedious is a conditional import.
    Workaround by just installing Tedious but it is a little tedious ;) having to bundle unnecessary modules

    Webpack build warnings and errors:

    WARNING in ./node_modules/sequelize/lib/dialects/mssql/connection-manager.js
    Module not found: Error: Can't resolve 'tedious' in '/Users/louiskw/Documents/GitHub/WhoTargetsMe-Backend/node_modules/sequelize/lib/dialects/mssql'
     @ ./node_modules/sequelize/lib/dialects/mssql/connection-manager.js 23:19-37
     @ ./node_modules/sequelize/lib/dialects/mssql/index.js
     @ ./node_modules/sequelize/lib/sequelize.js
     @ ./node_modules/sequelize/index.js
     @ ./src/db/models.js
     @ ./src/handler.js
    
    WARNING in ./node_modules/sequelize/lib/dialects/mysql/connection-manager.js
    Module not found: Error: Can't resolve 'mysql2' in '/Users/louiskw/Documents/GitHub/WhoTargetsMe-Backend/node_modules/sequelize/lib/dialects/mysql'
     @ ./node_modules/sequelize/lib/dialects/mysql/connection-manager.js 33:19-36
     @ ./node_modules/sequelize/lib/dialects/mysql/index.js
     @ ./node_modules/sequelize/lib/sequelize.js
     @ ./node_modules/sequelize/index.js
     @ ./src/db/models.js
     @ ./src/handler.js
    
    WARNING in ./node_modules/sequelize/lib/dialects/sqlite/connection-manager.js
    Module not found: Error: Can't resolve 'sqlite3' in '/Users/louiskw/Documents/GitHub/WhoTargetsMe-Backend/node_modules/sequelize/lib/dialects/sqlite'
     @ ./node_modules/sequelize/lib/dialects/sqlite/connection-manager.js 27:19-37
     @ ./node_modules/sequelize/lib/dialects/sqlite/index.js
     @ ./node_modules/sequelize/lib/sequelize.js
     @ ./node_modules/sequelize/index.js
     @ ./src/db/models.js
     @ ./src/handler.js
    
    WARNING in ./node_modules/sequelize/lib/sequelize.js
    374:61-74 Critical dependency: the request of a dependency is an expression
    
    WARNING in ./node_modules/sequelize/lib/dialects/mssql/connection-manager.js
    21:19-62 Critical dependency: the request of a dependency is an expression
    
    WARNING in ./node_modules/sequelize/lib/dialects/postgres/connection-manager.js
    21:16-59 Critical dependency: the request of a dependency is an expression
    
    WARNING in ./node_modules/sequelize/lib/dialects/mysql/connection-manager.js
    31:19-62 Critical dependency: the request of a dependency is an expression
    
    WARNING in ./node_modules/sequelize/lib/dialects/sqlite/connection-manager.js
    25:19-62 Critical dependency: the request of a dependency is an expression
    
    ERROR in ./node_modules/sequelize/lib/dialects/mssql/query.js
    Module not found: Error: Can't resolve 'tedious' in '/Users/louiskw/Documents/GitHub/WhoTargetsMe-Backend/node_modules/sequelize/lib/dialects/mssql'
     @ ./node_modules/sequelize/lib/dialects/mssql/query.js 10:14-32
     @ ./node_modules/sequelize/lib/dialects/mssql/index.js
     @ ./node_modules/sequelize/lib/sequelize.js
     @ ./node_modules/sequelize/index.js
     @ ./src/db/models.js
     @ ./src/handler.js
    
    ERROR in ./node_modules/pg/lib/native/client.js
    Module not found: Error: Can't resolve 'pg-native' in '/Users/louiskw/Documents/GitHub/WhoTargetsMe-Backend/node_modules/pg/lib/native'
     @ ./node_modules/pg/lib/native/client.js 10:13-33
     @ ./node_modules/pg/lib/native/index.js
     @ ./node_modules/pg/lib/index.js
     @ ./node_modules/sequelize/lib/dialects/postgres/connection-manager.js
     @ ./node_modules/sequelize/lib/dialects/postgres/index.js
     @ ./node_modules/sequelize/lib/sequelize.js
     @ ./node_modules/sequelize/index.js
     @ ./src/db/models.js
     @ ./src/handler.js
    
  8. Maushundb commented on Aug 26, 2017

    @Maushundb

    Same issue as @stunningpixels, would love to have this reopened as well.

  9. EdByrnee commented on Sep 3, 2017

    @EdByrnee

    Same issue

  10. corysimmons commented on Sep 20, 2017

    @corysimmons

    @janmeier Re-open until there's a solid workaround.

  11. louisremi commented on Sep 20, 2017

    @louisremi
    Contributor

    EDIT: my previous answer was wrong. To fix this problem, the easiest solution is to configure Webpack to make all your node_modules externals:

    externals: fs.readdirSync('node_modules').filter((x) => { return x !== '.bin'; }),

    see https://webpack.js.org/configuration/externals/
    and http://jlongster.com/Backend-Apps-with-Webpack--Part-I

  12. corysimmons commented on Sep 20, 2017

    @corysimmons

    Anyone in thread happen to know if Browserify/Rollup/etc suffer from this?

  13. kareljuricka commented on Oct 9, 2017

    @kareljuricka

    Similar problem here when build with webpack. Using webpack-node-externals to make node_modules externals but does not help.

    First possible workaround I found to build without errors is install all dialect libraries.

    Second possible workaround is add array ["pg", "sqlite3", "tedious", "pg-hstore"] to webpack externals, for me:

    externals: [nodeExternals(), ["pg", "sqlite3", "tedious", "pg-hstore"]]

    But warnings still remains - for example:

    WARNING in ./node_modules/sequelize/lib/sequelize.js 374:61-74 Critical dependency: the request of a dependency is an expression

    Inspirated from comment here angular/angular#11580 (comment) I rewrite this piece of code for sequelize, and warnings dissapeared:

    new webpack.ContextReplacementPlugin(
                /Sequelize(\\|\/)/,
                path.resolve(__dirname, '../src')
              )
    

    If anyone find better workaround, please write a comment. Also I agree that this issue should be reopened , as build bug using webpack.

  14. 26 remaining items

  15. Robert-Ernst commented on Apr 13, 2023

    @Robert-Ernst

    In AstroJS this is the intended way of solving this:

    In the root folder create a file with the name astro.config.mjs

    import { defineConfig } from "astro/config";
    export default defineConfig({
      vite: {
        optimizeDeps: {
          exclude: ['sequelize', 'sqlite3'],
        },
      }
    });
    

    Explanation:
    AstroJS uses Vite under the hood. This way it will be excluded from the build(?) process. I assume it tries to rebuild/treeshaking the dependencies. It works for me.

    Source:

  16. WikiRik commented on Apr 15, 2023

    @WikiRik
    Member

    I don't know what a webpack is, but I have been getting this issue when trying to make Sequelize work with npm

    And the funny thing is that Sequelize launches for me just fine if I use "node" to launch it.

    You're using parcel which is another bundler. From a quick Google search, I think using ignoreNodeModules could be used to ignore sequelize although I have no experience with using parcel

  17. SamuelBucher commented on Apr 15, 2023

    @SamuelBucher

    I don't know what a webpack is, but I have been getting this issue when trying to make Sequelize work with npm
    And the funny thing is that Sequelize launches for me just fine if I use "node" to launch it.

    You're using parcel which is another bundler. From a quick Google search, I think using ignoreNodeModules could be used to ignore sequelize although I have no experience with using parcel

    I already solved my issue. Turns out I just didn't have pg-hstore installed.

  18. manuchis commented on May 1, 2023

    @manuchis

    I had the same issue with NextJS 13, I've solved it by adding 'sequelize' to the 'next.config.mjs' under the 'experimental' label:
    const nextConfig = { output: 'standalone', experimental: { appDir: true, serverComponentsExternalPackages: ['sequelize'] } } module.exports = nextConfig;

  19. danielgzp commented on May 15, 2023

    @danielgzp

    I had the same issue with NextJS 13, I've solved it by adding 'sequelize' to the 'next.config.mjs' under the 'experimental' label: const nextConfig = { output: 'standalone', experimental: { appDir: true, serverComponentsExternalPackages: ['sequelize'] } } module.exports = nextConfig;

    This totally worked for me.

  20. tjgragg commented on May 30, 2023

    @tjgragg

    Sorry to bring this back up, but I'm getting this same error when trying to run sam build for an AWS lambda. Using Node/TS.
    I'm just trying to use sequelize with mysql2.

  21. WeiGrand commented on Jun 3, 2023

    @WeiGrand

    I had the same issue with NextJS 13, I've solved it by adding 'sequelize' to the 'next.config.mjs' under the 'experimental' label: const nextConfig = { output: 'standalone', experimental: { appDir: true, serverComponentsExternalPackages: ['sequelize'] } } module.exports = nextConfig;

    Same situation and this works for me. I just wonder why this work, can anyone explain it?

  22. EnkhAmar commented on Jun 15, 2023

    @EnkhAmar

    Sorry to bring this back up, but I'm getting this same error when trying to run sam build for an AWS lambda. Using Node/TS. I'm just trying to use sequelize with mysql2.

    I have same happened to me when trying use with mysql and node/ts . This occurs when i try to test my serverless function with
    sls offline

  23. EnkhAmar commented on Jun 16, 2023

    @EnkhAmar

    Sorry to bring this back up, but I'm getting this same error when trying to run sam build for an AWS lambda. Using Node/TS. I'm just trying to use sequelize with mysql2.

    I have same happened to me when trying use with mysql and node/ts . This occurs when i try to test my serverless function with sls offline

    I have solved it simply just putting 'pg-hstore' in exclude of esbuild.
    Config below is my serverless.ts

    custom: {
       ...other custom
    
        esbuild: {
          bundle: true,
          minify: false,
          sourcemap: true,
          exclude: ['aws-sdk', 'pg-hstore'],
          target: 'node18',
          define: { 'require.resolve': undefined },
          platform: 'node',
          concurrency: 10,
        },
      },
  24. Jan-T-Berg commented on Jun 16, 2023

    @Jan-T-Berg

    I make a new Next13 Application with src and app folder.

    install sequelize

    connect to mysql2 and get
    Module not found: Can't resolve 'pg-hstore'

    It works with:
    const nextConfig = { output: 'standalone', experimental: { appDir: true, serverComponentsExternalPackages: ['sequelize'] } } module.exports = nextConfig;

    but its bad for our CI/CD. Pls fix it

  25. ephys commented on Jun 16, 2023

    @ephys
    Member

    There is nothing to fix on our end. Marking these packages as external is exactly what you need to do. They are not designed to be bundled.

  26. unikitty37 commented on Aug 11, 2024

    @unikitty37

    @ephys Would it be worth at least mentioning this in the Getting Started page? It seems like a lot of people have ended up here trying to find out how to fix the problem, so it's maybe not as intuitive as you think…

    Edit: even after getting Vite to start, when using Sequelize 7 with SvelteKit, it still doesn't actually work properly:

    image

    I have precisely no idea how to fix this. IMHO, this code shouldn't even be trying to import @sequelize/mariadb:

      import { Sequelize } from '@sequelize/core'
      import { PostgresDialect } from '@sequelize/postgres'

    vite.config.ts:

    import { sveltekit } from '@sveltejs/kit/vite'
    import { defineConfig } from 'vitest/config'
    
    export default defineConfig({
      plugins: [sveltekit()],
      optimizeDeps: {
        exclude: [
          '@sequelize/snowflake',
          '@sequelize/db2',
          '@sequelize/db2-ibmi',
          '@sequelize/sqlite3',
          '@sequelize/mysql',
          '@sequelize/mssql',
          '@sequelize/mariadb',
        ],
      },
      test: {
        include: ['tests/unit/**/*.test.{js,ts}'],
      },
    })
  27. RLain commented on Oct 24, 2024

    @RLain

    Was getting the pg-hstore error in a monorepo. Tried the above solutions with partial success

    Then read about externals and have fixed everything by simply adding to the webpack.config:

    externals: 'sequelize'

    This worked for me.

    module.exports = {
        externals: {
            '@aws-sdk/client-secrets-manager': '@aws-sdk/client-secrets-manager',
            'sequelize': 'sequelize'
        },
      ...etc
    
  28. AlexanderPolenov commented on Dec 12, 2024

    @AlexanderPolenov

    To make it work with MySQL & NextJS 15+ add this to next.config.mjs:

    const nextConfig = {
        serverExternalPackages: ['sequelize'],
    };
    

    Also, when connect to DB use 127.0.0.1 and not the localhost. Because this will be the second problem that you will face.

  29. yueisme commented on Apr 6, 2025

    @yueisme

    this work for me:

    webpack.Configuration = {
      // ...other
      resolve: {
        fallback: {
          'pg-hstore': false,
        },
      },
    }
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