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

Dynamic import path does not work #8744

Closed
WayneUong opened this issue Jun 1, 2017 · 6 comments
Closed

Dynamic import path does not work #8744

WayneUong opened this issue Jun 1, 2017 · 6 comments

Comments

@WayneUong
Copy link

This works: import('/imports/client/main.js');
This doesn't work: import('/imports/client/' + 'main.js');

@dr-dimitru
Copy link
Contributor

@WayneUong does this produce an error? error stack?

@WayneUong
Copy link
Author

I got this error:

modules-runtime.js?hash=8587d18…:231 Uncaught (in promise) Error: Cannot find module '/imports/client/main.js'
    at makeMissingError (modules-runtime.js?hash=8587d18…:231)
    at Function.require.resolve (modules-runtime.js?hash=8587d18…:263)
    at Module.resolve (modules-runtime.js?hash=8587d18…:121)
    at modules-runtime.js?hash=8587d18…:183
    at meteor.js?hash=27829e9…:1105
    at <anonymous>

@benjamn
Copy link
Contributor

benjamn commented Jun 1, 2017

This is a deliberate design decision and not a bug: #8327 (comment)

tl;dr If you indicate elsewhere in your client code that the module should be made available (using import(id) where id is a statically analyzable string literal), then any dynamic expression will work in other places. However, the Meteor server will not make modules available for import unless your code expresses the dependency at build time.

@benjamn benjamn closed this as completed Jun 1, 2017
@dr-dimitru
Copy link
Contributor

@benjamn it's good to know, we should explicitly mention this in the documentation

@benjamn
Copy link
Contributor

benjamn commented Jun 1, 2017

@dr-dimitru good idea!

@hwillson
Copy link
Contributor

hwillson commented Jun 1, 2017

Thanks @dr-dimitru - I've created meteor/guide#641 so we don't lose track of this.

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

4 participants