SQL Scripts are missing when bundling with Webpack
Summary
The problem is raised by the error for any made request to DB (the stack trace is same as in #699 (closed)):
INFO Error TypeError: Invalid query format.
at h.f (/var/task/src/webpack:/node_modules/pg-promise/lib/query.js:60:17)
at h.call (/var/task/src/webpack:/node_modules/pg-promise/lib/query.js:259:23)
at call (/var/task/src/webpack:/node_modules/pg-promise/lib/database.js:326:42)
To be precise, the query was missing.
After looking deeply I found out that massive-js
was not able to load SQL queries from the scripts folder.
Those file were missing because the project was built with Webpack, which doesn't import .sql
by default.
Example
Database setup
CREATE TABLE things (
id SERIAL PRIMARY KEY,
stuff TEXT
);
Code demonstrating the behavior
Check out the repo I've created to reproduce the issue.
Workaround
The workaround that I've made is pretty "hacky" and there should be much better way to handle it, but here is the PR.
It uses transfer-webpack-plugin to copy over the SQL files from scripts
folder into the project and disables __dirname
Webpack injection.
Additional context
This ticket might be related to #699 (closed), but I'm assuming it deserves to be reported separately.
I also think Webpack is pretty frequently used for bundling JS/TS projects so it worths to find the solution.
@dmfay, please let me know if I'm missing configuration or something. I've looked through the issues and docs but didn't find any details about how to work with Webpack and MassiveJS. Thanks!