Generate import statements?


#1

I’m migrating my codebase from Meteor 1.2 to Meteor 1.3 and in the progress of rewriting all my global variables to nice import statements.

This seems like a very cumbersome process as my IDE (WebStorm) does not automatically recognizes the import paths for Meteor packages. I have to lookup and write basically everything myself.

Is there a quicker/automated process to do this? Surely I can’t be the only one who’s rewriting global variables to import statements for Meteor 1.3.


#2

I use webstorm too and it recognizes both import statement and sources to import from.

Have you set ES6 as your JS version? Have you updated WS?

I’m on linux, what OS are you using?


#3

I really doubt there’s any way to actually know where a module is coming from with any sense of certainty


#4

Thanks for your response.

I use the latest version of WebStorm on Mac and I have set my ecmascript version correctly.

When I type for example the keyword “Meteor” without having imported it, and I highlight the keyword Meteor, WebStorm does not give any suggestions for what to import. Not sure why


#5

I think there’s a confusion here.

Webstorm does resolve imports but it does not “suggest” imports as its big brother intellij does with java.


#6

Thanks for your answer. I guess I’ll have to lookup all imports myself then.


#7

@timw it turns out webstorm does offer automatic imports.

If it cannot resolve a symbol within the file itself and is exported somewhere else, there is a red lightbulb that appears at the beginning of he file with a caret and when you click on it, you’ll see it offering possible imports!

This does not currently work for JSX components, but it is a bug and is on the roadmap for a fix!


#8

I know this is how it works when I have filea.js and fileb.js in the same project, and I try to import a variable from filea.js into fileb.js.

However, this is not how it works for meteor packages. For example, when I write “FlowRouter” in a file, WebStorm does not suggest me to import it from the flow router package. Is there a workaround for this or do I simply wait until this is improved in WebStorm?


#9

Hmm yeah that’s right, meteor packages don’t actually get recognized for import suggestions. Did you post a feature request, even perhaps labeling it a bug report, over at the webstorm tracker? https://youtrack.jetbrains.com/oauth?state=%2F


#10

@timw @muaddib @corvid

it would be awesome it you upvoted this one that I just created

https://youtrack.jetbrains.com/issue/WEB-21901