我尝试使用Vue,Node和Webpack安装PostgreSQL。 我用这个样板
https://github.com/vuejs-templates/webpack
和
npm install pg
https://github.com/brianc/node-postgres
一旦我输入import pg from 'pg'
,我就会收到此错误消息。
These dependencies were not found:
* dns in ./node_modules/pg/lib/connection-parameters.js
* fs in ./node_modules/pgpass/lib/index.js
* net in ./node_modules/pg/lib/connection.js
* pg-native in ./node_modules/pg/lib/native/client.js
* tls in ./node_modules/pg/lib/connection.js
pg必须在webpack配置中设置为外部。这正是我做不到的。
如果我写下以下内容:externals: [{ pg: true }]
我在Chrome下收到此错误消息:
Uncaught ReferenceError: pg is not defined
at eval (webpack-internal:///41:1)
at Object.<anonymous> (app.js:996)
at __webpack_require__ (app.js:679)
at fn (app.js:89)
at eval (webpack-internal:///40:1)
at Object.<anonymous> (app.js:990)
at __webpack_require__ (app.js:679)
at fn (app.js:89)
at eval (webpack-internal:///38:1)
at Object.<anonymous> (app.js:977)
如何在webpack配置中正确输入pg?