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
[BUG] [2.5.6] import of npm library gives empty object #11900
Comments
Added a reproduction. |
@trusktr Awesome that you have a simple reproduction! For the record, this seems to specifically affect ES Modules (Material UI in my case), and the server build. I recently hit an unexpected issue recently when exploring ES modules, with NPM packages and Next.js: files with ".js" extensions maybe interpreted differently depending if
Maybe it's related? Like Meteor wrongly consider the package as CommonJS during the server build. For example DayJS is not explicitely using "type":"module": https://github.com/iamkun/dayjs/blob/dev/package.json nor using ".mjs" extension. For Material UI the package.json has: "main": "./node/index.js",
"module": "./index.js", |
Hi @trusktr, thank you for the detailed issue! I saw that you have the package I tested moving it to Can you try that? |
Meteor doesn't understand Node.js ESM or package.json
Ah, moving it from I think this might be considered a bug because all other tools (Webpack, Rollup, Parcel, etc) all successfully build an app regardless of which field dependencies are in, and this is in tuitive: tools (and node module resolution algorithm) care about what is in node_modules, not what is listed in dev vs non-dev dependencies. Another way to look at this is that having runtime dependencies in If we were to write a plain Node.js app, with The only time |
@denihs incredible I would never had imagined this to be the issue! Thanks a lot! It's consistent with my own experience with Material UI, as it was installed as a dev dependency in Vulcan. We use a Meteor app as a kind of a monorepo just for dev, so we have a lot of dev dependencies. |
This needs to be marked as a bug. |
After performing ❯ meteor --exclude-archs "web.browser.legacy, web.cordova"
[[[[[ ~/deleteme/mapapp ]]]]]
=> Started proxy.
=> Started HMR server.
=> Started MongoDB.
W20220407-20:53:38.794(-7)? (STDERR) /home/trusktr/.meteor/packages/meteor-tool/.2.7.1.tb7vzh.a2uk++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
W20220407-20:53:38.799(-7)? (STDERR) throw(ex);
W20220407-20:53:38.799(-7)? (STDERR) ^
W20220407-20:53:38.799(-7)? (STDERR)
W20220407-20:53:38.799(-7)? (STDERR) Error: Cannot find module "/node_modules/dayjs/esm/index.js". Try installing the npm package or make sure it is not a devDependency.
W20220407-20:53:38.799(-7)? (STDERR) at Module.useNode (packages/modules-runtime.js:647:11)
W20220407-20:53:38.799(-7)? (STDERR) at module (packages/modules.js:215:8)
W20220407-20:53:38.799(-7)? (STDERR) at fileEvaluate (packages/modules-runtime.js:336:7)
W20220407-20:53:38.799(-7)? (STDERR) at Module.require (packages/modules-runtime.js:238:14)
W20220407-20:53:38.799(-7)? (STDERR) at Module.moduleLink [as link] (/home/trusktr/.meteor/packages/modules/.0.18.0.1i29cl.iter++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:52:22)
W20220407-20:53:38.800(-7)? (STDERR) at module (imports/day.js:1:1)
W20220407-20:53:38.800(-7)? (STDERR) at fileEvaluate (packages/modules-runtime.js:336:7)
W20220407-20:53:38.800(-7)? (STDERR) at Module.require (packages/modules-runtime.js:238:14)
W20220407-20:53:38.800(-7)? (STDERR) at Module.moduleLink [as link] (/home/trusktr/.meteor/packages/modules/.0.18.0.1i29cl.iter++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:52:22)
W20220407-20:53:38.800(-7)? (STDERR) at module (server/imports/fixtures.js:1:1)
W20220407-20:53:38.800(-7)? (STDERR) at fileEvaluate (packages/modules-runtime.js:336:7)
W20220407-20:53:38.800(-7)? (STDERR) at Module.require (packages/modules-runtime.js:238:14)
W20220407-20:53:38.800(-7)? (STDERR) at Module.moduleLink [as link] (/home/trusktr/.meteor/packages/modules/.0.18.0.1i29cl.iter++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:52:22)
W20220407-20:53:38.800(-7)? (STDERR) at module (server/main.js:1:1)
W20220407-20:53:38.800(-7)? (STDERR) at fileEvaluate (packages/modules-runtime.js:336:7)
W20220407-20:53:38.800(-7)? (STDERR) at Module.require (packages/modules-runtime.js:238:14)
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.
^C In particular, note that the missing file does exist:
|
Here is a new reproduction that includes the meteor update: git clone git@github.com:trusktr/mapapp.git
cd mapapp
git checkout meteor-issue-11900-2
npm install
meteor --exclude-archs "web.browser.legacy, web.cordova" |
Hi, the solution on the PR was to throw a clear error message:
Did you make sure the package is not a devDependency? |
Hi, I find it unexpected that Meteor build differentiates between prod and dev dependencies (no other build engine I know does that), but at least the error message makes it more explicit indeed! Looks like it is also the case in above repro example: https://github.com/LUMECraft/mapapp/blob/meteor-issue-11900-2/package.json#L30 {
"devDependencies": {
"dayjs": "^1.10.7"
}
} |
Blocker: Unable to run a Meteor app because import of a library returns an empty object, as described in all these threads:
I don't know if this ever worked in previous versions of Meteor, but from the threads we can see the issue celebrated quite a few birthdays already.
I think @benjamn might have the most clue as to what this might be caused by; he architected Meteor's module system.
Meteor 2.5.6
Linux Ubuntu 21.10
Node.js v17.3.1
npm 8.3.1
Reproduction:
Error output:
The text was updated successfully, but these errors were encountered: