when using babel, pg-native is always required (and fails if not present)
See original GitHub issueI’m not sure if this is a Babel or a node-postgres bug, steps to reproduce:
export PATH=$PATH:/tmp/iojs-v3.0.0-linux-x64/bin/:./node_modules/.bin
mkdir t
cd t
npm install babel pg
# create a t.js file with this ES6 content:
import * as pg from "pg";
console.log(pg);
# now execute:
babel t.js > t-es5.js
node t-es5.js
Error: Cannot find module 'pg-native'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/tmp/o/node_modules/pg/lib/native/index.js:1:76)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Babel generates the following code in t-es5.js
:
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } }
var _pg = require("pg");
var pg = _interopRequireWildcard(_pg);
console.log(pg);
The exception is happening in the _interopRequireWildcard(_pg)
call. This doesn’t happens with other libraries, so I’m not sure if a Babel or a node-postgres bug.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:10
- Comments:36 (6 by maintainers)
Top Results From Across the Web
when using babel, pg-native is always required (and fails if not ...
I'm not sure if this is a Babel or a node-postgres bug, steps to reproduce: export PATH=$PATH:/tmp/iojs-v3.0.0-linux-x64/bin/:.
Read more >webpack import error with node-postgres ('pg'.Client)
The problem is an interaction between the way that node-postgres is written and how babel rewrites the code, which forces pg-native to be...
Read more >pg-native - npm
The callback is mandatory and is called with and Error if the execution failed, or with the same array of results as would...
Read more >Setting up a Serverless Project with Webpack, Babel, and Knex
Using Webpack with the Serverless Framework is handy if you want to use ... not found: Error: Can't resolve 'pg-native' Module not found: ......
Read more >API - esbuild
If you are using JavaScript be sure to check out the JS-specific details section ... if no input files are provided and the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another solution (if using webpack), is to add
new webpack.IgnorePlugin(/^pg-native$/)
to your webpack config’s plugins array. E.g.Nothing worked for me, so I created a manual fix myself
create a fix.js file at the root of the project:
to run the patch file whenever you update or install a new dependency, add it to the package.json file:
If you are using sequelize, make the following configuration in the configuration part: