We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I restricted the issue to a minimum lines of code.
Sources available in github.com/dsportes/bsql3
Regards
My server app runs with node v20 and I try to use only ES6 modules (not CommonJS ones), supposing that becomes the future sandard.
So in my app.js module:
import Database from 'better-sqlite3' // import { Database } from './loadreq.js' const db = Database(p) ...
It works. Just run: "npm run start"
Then I tried to build it with webpack. "npn run build"
In webpack.config.mjs I have an "externals" config:
externals: { // 'better-sqlite3': 'commonjs better-sqlite3' // Cannot find module 'better-sqlite3' // without the line above: TypeError: Cannot read properties of undefined (reading 'indexOf') }
Without "externals" configuration. When running "npm run test", I get:
Cannot read properties of undefined (reading 'indexOf')
After reading few topics I added the line 'better-sqlite3': 'commonjs better-sqlite3'
"npn run build" and then "npm run test", I get:
Cannot find module 'better-sqlite3'
which is normal, the better-sqlite3 module being excluded.
I have no solution for having an app packed with webpack using better-sqlite3 ES6.
So in my app.js module I change for using CommonJs invocation:
// import Database from 'better-sqlite3' import { Database } from './loadreq.js' const db = Database(p) ... loadreq.js: import { createRequire } from 'module' const require = createRequire(import.meta.url) export const Database = require('better-sqlite3')
Everything is OK.
Why using ES6 style causes troubles to Webpack and not CommonJs style ?
Any idea or workaround ?
The text was updated successfully, but these errors were encountered:
now we can use
import { createRequire } from "module"; const nodeRequire = createRequire(import.meta.url); const config = { client: "better-sqlite3", connection: { filename: path.join("./mysqlite.sqlite"), options: { nativeBinding: nodeRequire( "better-sqlite3/build/Release/better_sqlite3.node", ), }, }, useNullAsDefault: true, }; const db = knex(config);
Sorry, something went wrong.
It's old issue but maybe a solution will be useful to someone
const db = new SQLite('db_name.db', { nativeBinding: require('better-sqlite3/build/Release/better_sqlite3.node') })
No branches or pull requests
I restricted the issue to a minimum lines of code.
Sources available in github.com/dsportes/bsql3
Regards
My server app runs with node v20 and I try to use only ES6 modules (not CommonJS ones), supposing that becomes the future sandard.
So in my app.js module:
It works. Just run: "npm run start"
Then I tried to build it with webpack. "npn run build"
In webpack.config.mjs I have an "externals" config:
Without "externals" configuration. When running "npm run test", I get:
Cannot read properties of undefined (reading 'indexOf')
After reading few topics I added the line 'better-sqlite3': 'commonjs better-sqlite3'
"npn run build" and then "npm run test", I get:
Cannot find module 'better-sqlite3'
which is normal, the better-sqlite3 module being excluded.
I have no solution for having an app packed with webpack using better-sqlite3 ES6.
So in my app.js module I change for using CommonJs invocation:
Everything is OK.
Why using ES6 style causes troubles to Webpack and not CommonJs style ?
Any idea or workaround ?
The text was updated successfully, but these errors were encountered: