eliashussary / nutrition-facts

Food nutrition facts JSON API. Data provided by USDA Food Composition Databases.
https://ndb.nal.usda.gov/ndb/doc/index
27 stars 8 forks source link

TypeError: NutritionFacts is not a constructor #1

Closed roboflank closed 7 years ago

roboflank commented 7 years ago

const NF = new NutritionFacts(process.env.USDA_NDB_API_KEY); ^

TypeError: NutritionFacts is not a constructor

Am running into the above error. Any work around?

eliashussary commented 7 years ago

Can you share your script?

roboflank commented 7 years ago

Am just using the Demo script.

On Thu, Sep 28, 2017, 5:02 PM Elias Hussary notifications@github.com wrote:

Can you share your script?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eliashussary/nutrition-facts/issues/1#issuecomment-332846089, or mute the thread https://github.com/notifications/unsubscribe-auth/AGOuF2Nc8DWfUT0m5JmWOlwhAW0i6mtdks5sm6cMgaJpZM4Pm0Bo .

eliashussary commented 7 years ago

Okay, it was written using es6 modules oppose to commonjs.

Ensure you are importing/requiring correctly, notice the .default on my require statement.


// es6
import NutritionFacts from 'nutrition-facts'

// commonjs
const NutritionFacts = require('nutrition-facts').default
roboflank commented 7 years ago

Thanks :)

On Thu, Sep 28, 2017 at 7:04 PM, Elias Hussary notifications@github.com wrote:

Okay, it was written using es6 modules oppose to commonjs.

Ensure you are importing/requiring correctly, notice the .default on my require statement.

// es6import NutritionFacts from 'nutrition-facts' // commonjsconst NutritionFacts = require('nutrition-facts').default

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eliashussary/nutrition-facts/issues/1#issuecomment-332884192, or mute the thread https://github.com/notifications/unsubscribe-auth/AGOuF9Ecz9hqQyJFwjFoMcFkDRHOBV_Aks5sm8N2gaJpZM4Pm0Bo .