VulcanJS / Vulcan

🌋 A toolkit to quickly build apps with React, GraphQL & Meteor
http://vulcanjs.org
MIT License
7.98k stars 1.88k forks source link

Solve the mistery of empty object export for NPM packages #2580

Closed eric-burel closed 2 years ago

eric-burel commented 4 years ago

Issue has been seen there:

https://github.com/meteor/meteor/issues/10065 https://forums.meteor.com/t/importing-from-npm-returns-an-empty-object/44491 https://github.com/thereactivestack-legacy/meteor-webpack/issues/235 https://stackoverflow.com/questions/55382092/importing-gitlab-package-from-meteorjs-returns-empty-object https://forums.meteor.com/t/solved-require-import-npm-require-all-return-empty-object/50153/6 https://ethereum.stackexchange.com/questions/60335/web3-empty-object-server-side-in-meteor

The issue seems to appear eratically at different point in time, and different Meteor versions.

Had this issue when coding the automated backoffice, for material-ui icons and no-ssr. To be investigated.

image

eric-burel commented 4 years ago

Reproduction in Vulcan core repo:

Concerned file is packages/vulcan-ui-material/lib/components/backoffice/BackofficeNavbar.jsx, the failing import is the MenuIcon

eric-burel commented 4 years ago

Potential solution proposed by @captainn here:

Use a config similar to this, with babel-plugin-transform-imports

{

  "meteor": {
    "mainModule": {
      "client": "client/main.jsx",
      "server": "server/main.ts"
    },
    "testModule": "tests/main.ts",
    "nodeModules": {
      "recompile": {
        "simpl-schema": "legacy",
        "uniforms": true,
        "uniforms-material": true
      }
    }
  },
  "babel": {
    "plugins": [
      [
        "transform-imports",
        {
          "@material-ui/core": {
            "transform": "@material-ui/core/${member}",
            "preventFullImport": true
          },
          "@material-ui/icons": {
            "transform": "@material-ui/icons/${member}",
            "preventFullImport": true
          },
          "@material-ui/styles": {
            "transform": "@material-ui/styles/${member}",
            "preventFullImport": true
          },
          "uniforms": {
            "transform": "uniforms/src/${member}",
            "preventFullImport": true
          },
          "uniforms-material": {
            "transform": "uniforms-material/src/${member}",
            "preventFullImport": true
          }
        }
      ],
      "lodash",
      "npdev-react-loadable-babel"
    ]
  }
}
trusktr commented 2 years ago

@benjamn Would you graciously take a look at this long-standing issue with Meteor module loader?

eric-burel commented 2 years ago

Just for the record we have since migrated toward Next.js (https://vulcan-next.vercel.app/) and we have recently managed to mimick Meteor package architecture with NPM packages and Tsup (https://github.com/VulcanJS/npm-the-right-way/tree/main/my-package-tsup) but maybe this ticket could help detecting/fixing issues in Meteor. Let me know if you need help to reproduce.

trusktr commented 2 years ago

Opened a new Meteor issue with reproduction: https://github.com/meteor/meteor/issues/11900

eric-burel commented 2 years ago

Mystery solved : this bug affect specifically dev dependencies, and Material UI is a dev dependency in the Vulcan app 🎉 Now we simply need to wait for a fix in Meteor, see linked issue