简体   繁体   中英

How to import variable from external module

I'm a backend dev who happens to be working with some Node.JS code. I'd like to use some of the constants from module @aws-sdk/signature-v4 in my code, for example AMZ_DATE_QUERY_PARAM , which is shown in the docs. I can't figure out a way to import it.

Things I've tried that all led to AMZ_DATE_QUERY_PARAM = undefined :

  1. const { SignatureV4, AMZ_DATE_QUERY_PARAM } = require('@aws-sdk/signature-v4')
  2. import { AMZ_DATE_QUERY_PARAM } from '@aws-sdk/signature-v4'
  3. import sigV4 from '@aws-sdk/signature-v4'; const { AMZ_DATE_QUERY_PARAM } = sigV4;

Note that I also need SignatureV4 from the same module, so, the correct answer would show how to import both. I don't really care whether it's CommonJS or ES6 syntax, although ES6 is preferred.

Answering my own question:

import { AMZ_DATE_QUERY_PARAM } from "@aws-sdk/signature-v4/dist-cjs/constants.js";

This GitHub ticket is also relevant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM