使用vue将node-postgres添加到webpack

时间:2017-11-14 08:53:45

标签: node.js postgresql webpack external

我尝试使用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?

0 个答案:

没有答案