Skip to content
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

meteor/alanning:roles package creates Undefined export exception #246

Open
mattsouth opened this issue Nov 20, 2024 · 20 comments
Open

meteor/alanning:roles package creates Undefined export exception #246

mattsouth opened this issue Nov 20, 2024 · 20 comments

Comments

@mattsouth
Copy link

The meteor/alanning:roles package is a meteor community package and if I include it in a vanilla vue meteor 3.0.4 project then I see problems in the client build during validation that say:

UndefinedExportException: Could not import Meteor package into the client: export 'RolesCollection' is undefined
UndefinedExportException: Could not import Meteor package into the client: export 'RoleAssignmentCollection' is undefined

And a suggestion to raise an issue here (thankyou - that's a very clear steer). In development the issues can be fixed by disabling validation but this will stop a production build being created. The issue can be replicated by adding the package and then updating the imports/ui/Home.vue component to be:

<script setup>
import Hello from './Hello.vue'
import Info from './Info.vue'
import { Meteor } from 'meteor/meteor'
import { Roles } from 'meteor/alanning:roles'
import { computed } from 'vue'

const isAdmin = computed(() => Meteor.user() ? Roles.userIsInRole(Meteor.user()._id, ['admin']) : false)
</script>

<template>
  <h1 class="text-3xl font-bold my-6">Welcome to Meteor!{{ isAdmin ? ' (Admin)' : ''}}</h1>
  <Hello />
  <Info />
</template>
@JorgenVatle
Copy link
Owner

Interesting. I'll write up some test cases for this over next week and get back to you once I have more details. 👍

@mattsouth
Copy link
Author

@mattsouth
Copy link
Author

This issue still persists in meteor v3.1, using the core roles module. But I think my comment about not being to run this app in production is wrong - in my testing this morning I see I can run the app with meteor --production for both meteor 3.0.4 and 3.1 so it must have been another issue that was creating issues for me at the time.

@JorgenVatle
Copy link
Owner

JorgenVatle commented Nov 27, 2024

Just resolved some issues with the Meteor package parser which likely is related to the issue you were seeing there. The latest alpha build should have a fix for the issue available.

meteor remove jorgenvatle:vite-bundler
meteor add jorgenvatle:[email protected]

npm i meteor-vite@alpha

# The alpha build only supports Vite v6.
# If you're seeing peer dependency complaints from npm, run the following to upgrade Vite and Vue.
npm i vite@latest @vitejs/plugin-vue@latest

Let me know how it goes. 🤞

@mattsouth
Copy link
Author

mattsouth commented Nov 27, 2024

I was able to install and run the latest build but it didnt resolve the issue. In the browser console I still see:

Meteor-Vite package validation: 
Object { packageName: "meteor/roles", stubbedPackage: {…}, exportKeys: (3) […], warnOnly: true }
ValidateStub.ts:17:16
[meteor-vite] ⚠️ UndefinedExportException: Could not import Meteor package into the client: export 'RolesCollection' is undefined
    _a ValidateStub.ts:70
    _a3 ValidateStub.ts:77
    validateStub ValidateStub.ts:35
    validateStub ValidateStub.ts:27
    js roles:17
    fileEvaluate modules-runtime-hot.js:386
    require modules-runtime-hot.js:268
    require modules.js:299
    require modules-runtime-hot.js:308
    <anonymous> roles:24
ValidateStub.ts:45:27
[meteor-vite] ⚠️ UndefinedExportException: Could not import Meteor package into the client: export 'RoleAssignmentCollection' is undefined
    _a ValidateStub.ts:70
    _a3 ValidateStub.ts:77
    validateStub ValidateStub.ts:35
    validateStub ValidateStub.ts:27
    js roles:17
    fileEvaluate modules-runtime-hot.js:386
    require modules-runtime-hot.js:268
    require modules.js:299
    require modules-runtime-hot.js:308
    <anonymous> roles:24
ValidateStub.ts:45:27

These packages are defined here: https://github.com/meteor/meteor/blob/2e032970bfafebc33ccc79f14499e2a329770924/packages/roles/roles_common_async.js#L29

@mattsouth
Copy link
Author

FYI - current dependencies ....

meteor list
accounts-password       3.0.3  Password support for accounts
aldeed:collection2      4.0.4  Automatic validation of Meteor Mongo ...
aldeed:simple-schema    2.0.0  A simple schema validation object wit...
ecmascript              0.16.10  Compiler plugin that supports ES201...
es5-shim                4.8.1  Shims and polyfills to improve ECMASc...
hot-module-replacement  0.5.4  Update code in development without re...
jorgenvatle:vite        1.1.0-alpha.1  ⚡ Speeds up Meteor's build an...
meteor-base             1.5.2  Packages that every Meteor app needs
mizzao:user-status      2.0.0-rc.2  User connection and idle state t...
mobile-experience       1.1.2  Packages for a great mobile user expe...
mongo                   2.0.3  Adaptor for using MongoDB and Minimon...
montiapm:agent          3.0.0-beta.8* Performance Monitoring for Meteor
reactive-var            1.0.13  Reactive variable
roles                   1.0.0  Authorization package for Meteor
shell-server            0.6.1  Server-side component of the `meteor ...
standard-minifier-css   1.9.3  Standard css minifier used with Meteo...
standard-minifier-js    3.0.0  Standard javascript minifiers used wi...
static-html             1.4.0  Define static page content in .html f...
typescript              5.6.3  Compiler plugin that compiles TypeScr...
meteor npm list
myproject@ /home/matt/Software/myproject
├── @babel/[email protected]
├── @fortawesome/[email protected]
├── @fortawesome/[email protected]
├── @fortawesome/[email protected]
├── @openclinical/[email protected]
├── @popperjs/[email protected]
├── @types/[email protected]
├── @vitejs/[email protected]
├── @vue/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

@JorgenVatle
Copy link
Owner

JorgenVatle commented Nov 27, 2024

I initially thought there was an issue with the package parser, it seems like meteor/roles really is exporting undefined for both RolesCollection and RoleAssignmentCollection. 😅

Meteor-Vite was built to detect and abort builds when exports are missing as that was quite a big concern in versions prior to the fork. The module resolver should be fairly robust now, so you should probably be safe to just keep warnOnly enabled.

// vite.config.ts
defineConfig({
  plugins: [
    meteor({
      clientEntry: '...',
      stubValidation: {
        warnOnly: true
      }
    })
  ]
})

We're probably going to phase out the feature entirely down the line as Vite/Rollup already do a decent job of detecting when something isn't right. The warning messages might still show up in production though - I'll try to address that with the next release.

Just to clarify though, your production builds are passing right?

@mattsouth
Copy link
Author

Thanks for the write up. Is it worth raising an issue with the meteor team for the undefined exports? My production build is broken with the new jorgenvatle:vite package and vite 6. The app appears to build fine but then shows a blank page.

@JorgenVatle
Copy link
Owner

Alright, thanks for the clarification. Same issue with previous versions?

@mattsouth
Copy link
Author

mattsouth commented Nov 28, 2024

Yep, that's what I remember seeing when I first wrote this issue (with meteor 3.0.4) but for a while in the middle the production builds were working.

@JorgenVatle
Copy link
Owner

I see, would you be able to create a repository reproducing the issue by chance? I don't believe the issue is related to the meteor/roles package as builds seem to work fine on my end with the package in use. Though, I'm just importing it.

Are there any other warning messages that appear in the browser console?

@mattsouth
Copy link
Author

I cant yet reliably recreate this issue but intermittently in development I see this on startup:

$ meteor
[[[[[ ~/Software/meteor-vue-3.1 ]]]]]         

=> Started proxy.                             
=> Started HMR server.                        
=> Started MongoDB.                           
I20241129-09:26:57.938(0)? ⚡   Starting Vite server...
W20241129-09:26:57.942(0)? (STDERR) ⚡  You are using an out of date version of `meteor-vite`.
W20241129-09:26:57.942(0)? (STDERR)    Please update it: $ meteor npm i [email protected]
I20241129-09:26:58.077(0)? creating default users
(node:3407058) Warning: The `util._extend` API is deprecated. Please use Object.assign() instead.
(Use `node --trace-warnings ...` to show where the warning was created)
=> Started your app.

=> App running at: http://localhost:3000/
I20241129-09:26:58.322(0)? ⚡   Meteor-Vite ready for connections!
I20241129-09:26:58.329(0)? ⚡   Meteor-Vite ready for connections!
W20241129-09:26:59.233(0)? (STDERR) ⚡  [vite-dev-server] Connection to Meteor DDP server timed out!
I20241129-09:26:59.235(0)? ⚡  [vite-dev-server] [Background Worker] Shutting down...

which also yields a blank screen. Could this be related? Also note the out of date meteor-vite warning, (Im using 1.12.0). I'll keep trying.

@JorgenVatle
Copy link
Owner

JorgenVatle commented Dec 1, 2024

Oh, [email protected] expects a the ability to establish a connection with Meteor's DDP server. The inferred DDP URL might be invalid. You should be able to address this by explicitly setting your DDP connection URL. E.g. DDP_DEFAULT_CONNECTION_URL=localhost:3000 meteor --port 3000.

There is a hotfix for this that I just noticed has been pending release for a little while now. I'll see if I finish it up over the next couple days. In the meantime, I think the above command should resolve the issue for you.

@JorgenVatle
Copy link
Owner

The fix should be live now with #228

meteor npm i meteor-vite@latest
meteor add jorgenvatle:[email protected]

@mattsouth
Copy link
Author

roger that, I find a good config is ...

meteor:

which doesnt show the meteor-vite version message. I'll let you know if I see a white screen again.

@diavrank
Copy link

diavrank commented Dec 4, 2024

Could not import Meteor package into the client: export 'RolesCollection' is undefined
_a ValidateStub.ts:70

I got this issue as well by using the steps given for Meteor 3. So, after downgrading the vite version to v4 and and using the vite config accordingly to the jorgenvatle:vite-bundler package (instead of jorgenvatle:vite)

vite.config.ts

 plugins: [
        meteor({
            clientEntry: 'imports/startup/client/index.ts',
        }),
        vue(),
        vuetify({ autoImport: true }),
    ],
    optimizeDeps: {
        exclude: [
            'vue-meteor-tracker',
        ],
    },

package.json

"meteor": {
    "mainModule": {
      "client": "client/main.ts",
      "server": "server/main.ts"
    },
    "testModule": {
      "server": "tests/server/main.ts"
    }
  }

server/main.ts

import '/imports/startup/server';

client/main.ts_

//empty file

My repo example is this one . I intend to update vite to v6 to give you an example in how reproduce the Roles issue.

So, in short, I used the steps given for Meteor 2 even with my app in Meteor 3 and Vue 3.

@JorgenVatle
Copy link
Owner

JorgenVatle commented Dec 4, 2024

@diavrank Add the following to your MeteorVIte config. You can also set validation to "warnOnly" if you don't want builds to fail because of a missing export. Validation is strict by default intentionally throwing to prevent unwanted surprises in production in case a lazy-loaded package never gets included in your Meteor client bundle. For meteor/roles, two of its collection exports really are undefined, so it's safe to ignore.

plugins: [
  meteor({
    clientEntry: 'imports/startup/client/index.ts',
+   stubValidation: {
+     ignorePackages: ['meteor/roles'],
+   }
  }),
]

@diavrank
Copy link

diavrank commented Dec 6, 2024

Nice, will try later and let you know if the issue get fixed. Thanks for the tip @JorgenVatle .

@diavrank
Copy link

@JorgenVatle it worked with that config. Here is my PR with the changes in case it helps someone else :)

@diavrank
Copy link

Tested in production as well with disney meteor-base docker image :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants