-
Notifications
You must be signed in to change notification settings - Fork 26
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
Configure root-relative imports for JS (avoid import '../../..'
)
#77
Comments
Is the goal here to ensure that all JS files should be in |
@vibalre I updated the issue description; I hope it is clear now 🙂 |
Issue #77 Found the best explanation here: https://webpack.js.org/configuration/resolve/#resolvealias With this setting, all files and folders in js can now be referenced with the js alias, e.g. a module app/js/module.js should be imported in index.js as js/module.js. app/js/foo/hello.js should be imported in index.js as js/foo/hello.js.
@kamilzyla so far I have only figured out to make it work with We can configure My problem now is how I can do the same with I see that we have |
@vibalre Ideally with some configuration we'd get ESLint to to read the alias from the Webpack config so that we wouldn't need to repeat the alias definition (DRY). I think I had such a setup in one project - please research if we could do it in Rhino. In general, the fewer dependencies the better, but if adding another package helps us- let's do it. Perhaps we should remove |
@kamilzyla I agree about keeping it DRY as much as possible.
Using Webpack AliasI agree that we should be able to use the alias in webpack config. I learned that we also have
However, I encountered two major errors: no babel config file detected and No Babel Config File
From the error above, I can confirm that eslint is using the correct alias and path to the js file (other modules used in My solution for this was to follow the error's suggestion and set
I am assuming the parser will then use the default babel config file. Correct me if I am wrong. Space in the PathMy user folder unfortunately has a space, e.g. instead of When I run
I spent some time trying to figure out how to fix this error, but I could not find a good solution. I guess it is not good practice to have a space in the user folder (or any file path), but I think spaces in paths is not uncommon, so this might become a recurring issue. My only workaround is to turn
I am suggesting this as a form of desperation. 😅 A possible alternative would be to use I converted this into a StackOverflow question. |
Current changes to |
Thanks for your research @vibalre! I want to take a deeper look tomorrow, but here are a couple of notes for now:
|
|
As an experiment I tried the following:
Now some important things to notice: before step (5) we get "No Babel config file detected" and "import/no-extraneous-dependencies". It seems that the Babel issue is crucial though: same errors appear if we try to import a non-existent object, e.g. ThoughtsAll our problems here seem to stem from the fact that we are using the |
Issue #77 Found the best explanation here: https://webpack.js.org/configuration/resolve/#resolvealias With this setting, all files and folders in js can now be referenced with the js alias, e.g. a module app/js/module.js should be imported in index.js as js/module.js. app/js/foo/hello.js should be imported in index.js as js/foo/hello.js.
Issue #77 Found the best explanation here: https://webpack.js.org/configuration/resolve/#resolvealias With this setting, all files and folders in js can now be referenced with the js alias, e.g. a module app/js/module.js should be imported in index.js as js/module.js. app/js/foo/hello.js should be imported in index.js as js/foo/hello.js.
Marking as blocked after finding another obstacle. |
Background
A root-relative path is a path interpreted relative to the project root. For example, in
app/view/table.R
you can havebox::use(app/logic/constants)
and it will be interpreted asapp/logic/constants.R
and NOT e.g.app/view/app/logic/constants.R
.Problem
Our current setup doesn't allow root-relative import paths in JS. Say we have files
app/js/foo/hello.js
andapp/js/bar/bye.js
. You need to use..
to importbye.js
fromhello.js
:Using
..
in import statements makes the code less readable and maintainable. It would be preferable to do something like this instead:Notes
We can probably achieve this via some Webpack config. Consider what would be the best prefix to use for root-relative paths:
app/js/
seems the most natural but somewhat verbose; it could be e.g.js/
or@js/
(interpreted relative toapp/
).The text was updated successfully, but these errors were encountered: