Skip to content

Instantly share code, notes, and snippets.

@ronkot
Last active August 1, 2016 12:36
Show Gist options
  • Save ronkot/2babe4b777d7bcb4053b9747d9c59346 to your computer and use it in GitHub Desktop.
Save ronkot/2babe4b777d7bcb4053b9747d9c59346 to your computer and use it in GitHub Desktop.
babel-plugin-rewire problem
{
"presets": ["es2015", "es2015-node4", "async-to-bluebird"],
"env": {
"test": {
"plugins": ["babel-plugin-rewire"]
}
}
}
{
"name": "api",
"version": "0.0.1",
"private": true,
"description": "New Swagger API Project",
"keywords": [],
"author": "",
"license": "",
"main": "app.js",
"dependencies": {
"babel-core": "^6.10.4",
"babel-eslint": "^4.1.6",
"babel-polyfill": "^6.3.14",
"babel-preset-async-to-bluebird": "^1.0.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-es2015-node4": "^2.0.2",
"babel-register": "^6.3.13",
"bluebird": "^3.1.1",
"body-parser": "^1.15.1"
},
"devDependencies": {
"babel-plugin-rewire": "^1.0.0-rc-3",
"mocha": "^2.5.3",
"should": "^7.1.0"
},
"scripts": {
"test": "NODE_ENV=test mocha --compilers js:babel-register --require babel-polyfill --require should"
}
}
'use strict'
const should = require('should')
try {
console.log('should through variable: ', should)
} catch (error) {
console.log(error)
}
console.log('should through require: ', require('should'))
@ronkot
Copy link
Author

ronkot commented Aug 1, 2016

For some reason the should library cannot be required to variable.

To reproduce, run: npm install && npm test
To fix the import error (but break rewire functionality), comment out the rewire plugin from .babelrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment