-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we add support of ES6 import / export modules? #1
Comments
export default request Would you like to import anything other than the main request function into your code? Or is your question a more basic one? Then the answer would be: Yes, you can use |
I just want to be consistent in my codebase. I can easily do:
but
doesn't work :( |
Unfortunately, I don't have a test set up for that so please give me more input:
|
|
Alright, thanks. The issue is not urgent since you can still use |
Just a heads up I am using babel for transpiling ES6 and |
Thanks @ericmwalsh , good to know! |
Maybe now that Node v0.12 has reach EOL this can be done? |
Just tried IOW request-promise-native already supports it & @analog-nico, I think you can close this issue. |
Try using node with
Currently getting,
|
Really though it seems like this whole approach is wrong. Moving forward at some point for posterity I would expect |
@EvanCarroll
I've filed an issue with core node here: nodejs/help#1717 |
If anyone is still struggling with this and isn't using a transpiler that handles this, here is an example of how babel manages to get both es6 imports and require to work: import lorem from "ipsum"; becomes var _ipsum = _interopRequireDefault(require("ipsum"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
// tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"strictNullChecks": false,
"target": "es2015"
},
"compileOnSave": true,
"include": [
"src"
]
} // package.json
{
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
...
},
"dependencies": {
"request-promise-native": "^1.0.7",
...
},
"devDependencies": {
"@types/node": "^12.0.2",
"@types/request-promise-native": "^1.0.16",
"tslint": "^5.12.0",
"typescript": "^3.5.1",
...
}
} import * as request from 'request-promise-native';
const uri = 'https://api.example.com';
const options = {
headers: {
'User-Agent': 'CustomAPI'
},
json: true
};
request(uri, options)
.then(response => {
console.log('response', response);
return response;
})
.catch(error => {
return error;
});
Works for me on Firebase Cloud Functions, and I'm not using babel. I'm using the Node 8 engine on Firebase Cloud Functions for async/await support. |
I am having the same issue when I am not using any compiler (babel, etc) |
No description provided.
The text was updated successfully, but these errors were encountered: