hotwired / stimulus-rails

Use Stimulus in your Ruby on Rails app
https://stimulus.hotwired.dev
MIT License
637 stars 91 forks source link

Fixed example in the readme #115

Closed berti92 closed 3 months ago

berti92 commented 1 year ago

If I use import controllers as mentioned in the README I get the following error:

13:15:21 js.1   |   errors: [
13:15:21 js.1   |     {
13:15:21 js.1   |       detail: undefined,
13:15:21 js.1   |       id: '',
13:15:21 js.1   |       location: {
13:15:21 js.1   |         column: 7,
13:15:21 js.1   |         file: 'application.js',
13:15:21 js.1   |         length: 13,
13:15:21 js.1   |         line: 24,
13:15:21 js.1   |         lineText: 'import "controllers";',
13:15:21 js.1   |         namespace: '',
13:15:21 js.1   |         suggestion: '"./controllers"'
13:15:21 js.1   |       },
13:15:21 js.1   |       notes: [
13:15:21 js.1   |         {
13:15:21 js.1   |           location: null,
13:15:21 js.1   |           text: 'Use the relative path "./controllers" to reference the file "controllers/index.js". Without the leading "./", the path "controllers" is being interpreted as a package path instead.'
13:15:21 js.1   |         }
13:15:21 js.1   |       ],
13:15:21 js.1   |       pluginName: '',
13:15:21 js.1   |       text: 'Could not resolve "controllers"'
13:15:21 js.1   |     }
13:15:21 js.1   |   ],
13:15:21 js.1   |   warnings: []
13:15:21 js.1   | }
13:15:21 js.1   | error Command failed with exit code 1.
13:15:21 js.1   | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
13:15:21 js.1   | exited with code 1

I fixed the error by implementing the suggested "./controllers".

I don't know if the same error occurs with importmap, because I don't use it.

marcoroth commented 1 year ago

Hey @berti92, thanks for opening this pull request!

Yeah, sadly this is because the different solutions/bundlers are using a different import syntaxes.

Instead of changing it in-place we can maybe say that import "controllers" is for importmaps/webpack(er) and import "./controllers for esbuild.

berti92 commented 1 year ago

@marcoroth Thank you, I changed it.

dhh commented 3 months ago

We already have a section for importmaps that use the correct import syntax for that. We should default to ./controllers for that other section. It's an error that it hadn't been.