I am trying to connect my database in Node.js but I am getting the error liquibase is not a function
. I did install the module using npm install liquibase
. Why am I getting this error?
const liquibase = require('liquibase');
liquibase({
changeLogFile: 'resources/liquibase/db.changelog.xml',
url: 'jdbc:postgresql://localhost:5432/postgres',
username: 'postgres',
password: 'admin'
})
.run('<action>', '<action-params>')
.then(() => console.log('success'))
.catch((err) => console.log('fail', err));
Error: Cannot find module 'node-liquibase'
Require stack:
- C:\Users\fabio\OneDrive\Ambiente de Trabalho\LiquibaseNode\index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Users\fabio\OneDrive\Ambiente de Trabalho\LiquibaseNode\index.js:1:19)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\fabio\\OneDrive\\Ambiente de Trabalho\\LiquibaseNode\\index.js'
]
}
Here's a link to the docs for Node errors.
MODULE_NOT_FOUND
A module file could not be resolved while attempting a require() or import operation.
My guess is that node-liquibase
is not installed in your application's node_modules
directory, and/or is not installed globally on your host machine.
Other commenters have already caught some of the issues I was going to mention, and I would also encourage taking a look at the documentation for using it in JavaScript files . There were a few bugs in your original post that are resolved by making sure you're importing the right package and using it correctly.
If you're still having issues, here are the steps I would take if I were in your position:
node_modules
directory in the root of my Node applicationnode_modules/liquibase
also exists in the root of my Node application Here's an example of the tree structure for the Node Liquibase Sandbox example repo . This will show what a working node-liquibase
consuming project could look like:
.
├── README.md
├── assets
│ └── img
├── changelog.xml
├── db-start-up.sh
├── index.ts
├── node_modules
│ ├── @types
│ ├── liquibase
│ ├── tslib
│ └── typescript
├── package.json
├── testing.js
├── tsconfig.esm.json
├── tsconfig.json
└── yarn.lock
In this example there's package.json
file that defines all of the metadata about your Node application, and as a direct 'sibling' there's a node_modules
directory that has this application's installed version of node-liquibase
.
TLDR; Basically your app is asking for node-liquibase
but Node can't find it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.