webpack与node-postgres导入错误('pg'.Client)

试图用Webpack捆绑下面的文件失败

错误:./~/pg/lib/native/index.js模块未find:错误:无法parsing模块'pg-native'in … / node_modules / pg / lib / native @ ./~/pg/lib/ native / index.js 9:13-33

我在.babelrc尝试了几个ignore语句,但没有得到它运行…

我想捆绑的testing文件: handler.js

 const Client = require('pg').Client; console.log("done"); 

webpack.config.js

 module.exports = { entry: './handler.js', target: 'node', module: { loaders: [{ test: /\.js$/, loaders: ['babel'], include: __dirname, exclude: /node_modules/, }] } }; 

.babelrc

 { "plugins": ["transform-runtime"], "presets": ["es2015", "stage-1"] } 

的package.json

 "dependencies": { "postgraphql": "^2.4.0", "babel-runtime": "6.11.6" }, "devDependencies": { "babel-core": "^6.13.2", "babel-loader": "^6.2.4", "babel-plugin-transform-runtime": "^6.12.0", "babel-preset-es2015": "^6.13.2", "babel-preset-stage-0": "^6.5.0", "babel-polyfill": "6.13.0", "serverless-webpack": "^1.0.0-rc.3", "webpack": "^1.13.1" } 

有些相关的github问题:

  • https://github.com/brianc/node-postgres/issues/1187
  • https://github.com/serverless/serverless-runtime-babel/issues/8

你必须安装pg-native

 npm install pg-native