[Solved] require/import/Npm.require() all return empty object

I’ve got an issue where installing @paypal/checkout-server-sdk via npm results in an empty object upon require(‘@paypal/checkout-server-sdk’) or import paypal from ‘@paypal/checkout-server-sdk’ or Npm.require(…).

If I create a test.js file in my project’s root directory and require() the package and run ‘node test.js’, I can print out the expected result just fine. Any ideas what might be happening here?

I’ve tried…:

  • deleting node_modules and doing ‘meteor npm install’
  • Running madge to find circular deps (found a few - e.g. jQuery - but didn’t see any that looked at all related)
  • Using import, require, Npm.require(). All result in empty objects.

I’m using Meteor v1.8.1 and the latest @paypal/checkout-server-sdk as of Sept 2019.

Any ideas of might be going on or what I might try next?

Thank you!

Very strange. I just spun up a new project to test and it’s working fine:

  1. meteor create paypal-import-test
  2. cd paypal-import-test
  3. meteor npm install @paypal/checkout-server-sdk
  4. Add import paypal from '@paypal/checkout-server-sdk' to server/main.js
  5. meteor run
  6. In a separate tab meteor shell
  7. Run require('@paypal/checkout-server-sdk') in the shell
  8. Which returns { core: {...}, orders: {...}, payments: {...} }

Can you post the code where you’re importing it and how you’re using it? It’s likely just a syntax error

1 Like

Hey, thanks for taking the time…

So I’ve got it working now. Nothing changed in my code, but somehow I managed to do something with NPM to remove @paypal/checkout-server-sdk from package.json. I’ve looked carefully at my zsh history and git commits and it still isn’t clear to me what happened. But: it works now. Again, thank you for taking the time.

I’m wondering if I mixed ‘meteor npm’ with ‘npm’…nope, they’re both 6.9.0, so I suppose that shouldn’t matter.

I did have to do ‘meteor npm audit fix’, but that shouldn’t remove a package. Duno how it got removed. Anyway, thanks again!

1 Like

Again with this!

I just installed a different NPM package and it’s requiring()/importing as an empty object.

All I did:

meteor npm i --save dropbox-v2-api

In my app:

import dropboxV2Api from ‘dropbox-v2-api’
console.log(dropboxV2Api)

Using require() yields the same result, which is {}.

Any thoughts?

I’ve tried doing ‘meteor npm install’ which does nothing. My package.json looks like this:

{
  "name": "<my app name>",
  "private": true,
  "scripts": {},
  "dependencies": {
    "@babel/runtime": "^7.4.5",
    "@easypost/api": "^3.7.0",
    "@paypal/checkout-server-sdk": "^1.0.1",
    "@vimeo/player": "^2.8.2",
    "adaptive-bezier-curve": "^1.0.3",
    "async": "^2.6.2",
    "aws-cloudfront-sign": "^2.2.0",
    "aws-sdk": "^2.463.0",
    "babel-polyfill": "^6.26.0",
    "babel-runtime": "^6.26.0",
    "batchelor": "^2.0.2",
    "bcrypt": "^3.0.6",
    "bitly": "^6.0.8",
    "clone-deep": "^4.0.1",
    "cookieconsent": "^3.1.0",
    "core-js": "^2.6.5",
    "date-diff": "^0.2.1",
    "detector-webgl": "^2.0.0",
    "dropbox-v2-api": "^2.4.5",
    "filepond": "^4.4.7",
    "filepond-plugin-file-validate-size": "^2.1.3",
    "filepond-plugin-image-exif-orientation": "^1.0.6",
    "filepond-plugin-image-preview": "^4.1.1",
    "format-email": "^0.1.0",
    "google-spreadsheet": "^2.0.7",
    "googleapis": "^39.2.0",
    "hls.js": "^0.10.2-canary.3983",
    "i18n-iso-countries": "^3.7.8",
    "iplocation": "^6.1.0",
    "jquery": "^3.4.1",
    "js-base64": "^2.5.1",
    "lodash": "^4.17.15",
    "md5": "^2.2.1",
    "meteor-node-stubs": "^0.4.1",
    "mimemessage": "^1.0.5",
    "mongodb": "^2.2.36",
    "postprocessing": "^6.5.0",
    "qrcode-reader": "^1.0.4",
    "random-seed": "^0.3.0",
    "request": "^2.88.0",
    "request-promise-native": "^1.0.7",
    "shippo": "^1.3.1",
    "sprintf": "^0.1.5",
    "stats.js": "^0.17.0",
    "stripe": "^6.30.0",
    "three": "^0.105.2",
    "three-line-2d": "^1.1.6",
    "useragent": "^2.3.0",
    "yamlparser": "0.0.2"
  },
  "devDependencies": {
    "command-line-args": "^5.1.1",
    "command-line-usage": "^5.0.5",
    "currency-converter": "^0.1.12",
    "gm": "^1.23.1",
    "replace-ext": "^1.0.0"
  }
}

My package-lock.json is too long to paste here. Link: https://pastebin.com/CLxEE89V

FIXED:

rm -rf node_modules
meteor npm install
<restart server>

:expressionless:

This issue reappears erratically… Had the same with @material-ui/icons@4.9 but removing node_modules and reinstalling does not seem to be enough.