rails / jsbundling-rails

Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.
MIT License
831 stars 143 forks source link

Could not resolve "@hotwired/turbo-rails" #149

Closed unixc3t closed 1 year ago

unixc3t commented 1 year ago

OS: Manjaro Linux x86_64 yarn 1.22.19 node: v19.7.0 ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux] Rails 7.0.4.2

package.json

 {
  "name": "app",
  "private": "true",
  "dependencies": {
    "@hotwired/stimulus": "^3.2.1",
    "@hotwired/turbo-rails": "^7.2.5",
    "@popperjs/core": "^2.11.6",
    "bootstrap": "^5.2.3",
    "bootstrap-icons": "^1.10.3",
    "esbuild": "^0.17.10",
    "sass": "^1.58.3"
  },
  "scripts": {
    "build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=assets",
    "build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
  }

node_modules:

    ├── anymatch
├── binary-extensions
├── bootstrap
│   ├── dist
│   │   ├── css
│   │   └── js
│   ├── js
│   │   ├── dist
│   │   │   ├── dom
│   │   │   └── util
│   │   └── src
│   │       ├── dom
│   │       └── util
│   └── scss
│       ├── forms
│       ├── helpers
│       ├── mixins
│       ├── utilities
│       └── vendor
├── bootstrap-icons
│   ├── font
│   │   └── fonts
│   └── icons
├── braces
│   └── lib
├── chokidar
│   ├── lib
│   └── types
├── @esbuild
│   └── linux-x64
│       └── bin
├── esbuild
│   ├── bin
│   └── lib
├── fill-range
├── glob-parent
├── @hotwired
│   ├── stimulus
│   │   └── dist
│   │       └── types
│   │           ├── core
│   │           ├── multimap
│   │           ├── mutation-observers
│   │           └── tests
│   │               ├── cases
│   │               ├── controllers
│   │               ├── fixtures
│   │               │   └── application_start
│   │               └── modules
│   │                   ├── core
│   │                   └── mutation-observers
│   ├── turbo
│   │   └── dist
│   │       └── types
│   │           ├── core
│   │           │   ├── drive
│   │           │   ├── frames
│   │           │   ├── native
│   │           │   └── streams
│   │           ├── elements
│   │           ├── http
│   │           ├── observers
│   │           ├── polyfills
│   │           └── tests
│   │               ├── functional
│   │               ├── helpers
│   │               ├── integration
│   │               └── unit
│   └── turbo-rails
│       └── app
│           ├── assets
│           │   └── javascripts
│           └── javascript
│               └── turbo
├── immutable
│   └── dist
├── is-binary-path
├── is-extglob
├── is-glob
├── is-number
├── normalize-path
├── picomatch
│   └── lib
├── @popperjs
│   └── core
│       ├── dist
│       │   ├── cjs
│       │   ├── esm
│       │   │   ├── dom-utils
│       │   │   ├── modifiers
│       │   │   └── utils
│       │   └── umd
│       └── lib
│           ├── dom-utils
│           ├── modifiers
│           └── utils
├── @rails
│   └── actioncable
│       ├── app
│       │   └── assets
│       │       └── javascripts
│       └── src
├── readdirp
├── sass
│   └── types
│       ├── legacy
│       ├── logger
│       ├── util
│       └── value
├── source-map-js
│   └── lib
└── to-regex-range

1 I use rails new -c bootstrap app1 2 run bin/dev

error:

    $ esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=assets --watch
16:12:15 css.1  | $ sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules --watch
16:12:15 js.1   | [watch] build finished, watching for changes...
16:12:15 js.1   | ✘ [ERROR] Could not resolve "@hotwired/turbo-rails"
16:12:15 js.1   | 
16:12:15 js.1   |     app/javascript/application.js:2:7:
16:12:15 js.1   |       2 │ import "@hotwired/turbo-rails"
16:12:15 js.1   |         ╵        ~~~~~~~~~~~~~~~~~~~~~~~
16:12:15 js.1   | 
16:12:15 js.1   |   The Yarn Plug'n'Play manifest forbids importing "@hotwired/turbo-rails" here because it's not listed as a dependency of this package:
16:12:15 js.1   | 
16:12:15 js.1   |     ../../../../.pnp.cjs:38:33:
16:12:15 js.1   |       38 │           "packageDependencies": [\
16:12:15 js.1   |          ╵                                  ~~
16:12:15 js.1   | 
16:12:15 js.1   |   You can mark the path "@hotwired/turbo-rails" as external to exclude it from the bundle, which will remove this error.
16:12:15 js.1   | 
16:12:15 js.1   | ✘ [ERROR] Could not resolve "bootstrap"
16:12:15 js.1   | 
16:12:15 js.1   |     app/javascript/application.js:4:27:
16:12:15 js.1   |       4 │ import * as bootstrap from "bootstrap"
16:12:15 js.1   |         ╵                            ~~~~~~~~~~~
16:12:15 js.1   | 
16:12:15 js.1   |   The Yarn Plug'n'Play manifest forbids importing "bootstrap" here because it's not listed as a dependency of this package:
16:12:15 js.1   | 
16:12:15 js.1   |     ../../../../.pnp.cjs:38:33:
16:12:15 js.1   |       38 │           "packageDependencies": [\
16:12:15 js.1   |          ╵                                  ~~
16:12:15 js.1   | 
16:12:15 js.1   |   You can mark the path "bootstrap" as external to exclude it from the bundle, which will remove this error.
16:12:15 js.1   | 
16:12:15 js.1   | ✘ [ERROR] Could not resolve "@hotwired/stimulus"
16:12:15 js.1   | 
16:12:15 js.1   |     app/javascript/controllers/hello_controller.js:1:27:
16:12:15 js.1   |       1 │ import { Controller } from "@hotwired/stimulus"
16:12:15 js.1   |         ╵                            ~~~~~~~~~~~~~~~~~~~~
16:12:15 js.1   | 
16:12:15 js.1   |   The Yarn Plug'n'Play manifest forbids importing "@hotwired/stimulus" here because it's not listed as a dependency of this package:
16:12:15 js.1   | 
16:12:15 js.1   |     ../../../../.pnp.cjs:38:33:
16:12:15 js.1   |       38 │           "packageDependencies": [\
16:12:15 js.1   |          ╵                                  ~~
16:12:15 js.1   | 
16:12:15 js.1   |   You can mark the path "@hotwired/stimulus" as external to exclude it from the bundle, which will remove this error.
16:12:15 js.1   | 
16:12:15 js.1   | ✘ [ERROR] Could not resolve "@hotwired/stimulus"
16:12:15 js.1   | 
16:12:15 js.1   |     app/javascript/controllers/application.js:1:28:
16:12:15 js.1   |       1 │ import { Application } from "@hotwired/stimulus"
16:12:15 js.1   |         ╵                             ~~~~~~~~~~~~~~~~~~~~
16:12:15 js.1   | 
16:12:15 js.1   |   The Yarn Plug'n'Play manifest forbids importing "@hotwired/stimulus" here because it's not listed as a dependency of this package:
16:12:15 js.1   | 
16:12:15 js.1   |     ../../../../.pnp.cjs:38:33:
16:12:15 js.1   |       38 │           "packageDependencies": [\
16:12:15 js.1   |          ╵                                  ~~
16:12:15 js.1   | 
16:12:15 js.1   |   You can mark the path "@hotwired/stimulus" as external to exclude it from the bundle, which will remove this error.
16:12:15 js.1   | 
16:12:15 js.1   | 4 errors
16:12:15 web.1  | => Booting Puma
16:12:15 web.1  | => Rails 7.0.4.2 application starting in development 
16:12:15 web.1  | => Run `bin/rails server --help` for more startup options
16:12:15 web.1  | Puma starting in single mode...
16:12:15 web.1  | * Puma version: 5.6.5 (ruby 3.1.2-p20) ("Birdie's Version")
16:12:15 web.1  | *  Min threads: 5
16:12:15 web.1  | *  Max threads: 5
16:12:15 web.1  | *  Environment: development
16:12:15 web.1  | *          PID: 97738
16:12:15 web.1  | * Listening on http://127.0.0.1:3000
16:12:15 web.1  | * Listening on http://[::1]:3000
16:12:15 web.1  | Use Ctrl-C to stop
16:12:16 css.1  | Sass is watching for changes. Press Ctrl-C to stop.
unixc3t commented 1 year ago

this is install info

        run  bundle binstubs bundler
       rails  javascript:install:esbuild
Compile into app/assets/builds
      create  app/assets/builds
      create  app/assets/builds/.keep
      append  app/assets/config/manifest.js
      append  .gitignore
      append  .gitignore
Add JavaScript include tag in application layout
      insert  app/views/layouts/application.html.erb
Create default entrypoint in app/javascript/application.js
      create  app/javascript
      create  app/javascript/application.js
Add default package.json
      create  package.json
Add default Procfile.dev
      create  Procfile.dev
Ensure foreman is installed
         run  gem install foreman from "."
Successfully installed foreman-0.87.2
1 gem installed
Add bin/dev to start foreman
      create  bin/dev
Install esbuild
         run  yarn add esbuild from "."
yarn add v1.22.19
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 2 new dependencies.
info Direct dependencies
└─ esbuild@0.17.10
info All dependencies
├─ @esbuild/linux-x64@0.17.10
└─ esbuild@0.17.10
Done in 3.99s.
Add build script
         run  npm pkg set scripts.build="esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=assets" from "."
         run  yarn build from "."
yarn run v1.22.19
$ esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=assets

  app/assets/builds/application.js      62b 
  app/assets/builds/application.js.map  93b 

Done in 0.13s.
       rails  turbo:install stimulus:install
Import Turbo
      append  app/javascript/application.js
Install Turbo
         run  yarn add @hotwired/turbo-rails from "."
yarn add v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 3 new dependencies.
info Direct dependencies
└─ @hotwired/turbo-rails@7.2.5
info All dependencies
├─ @hotwired/turbo-rails@7.2.5
├─ @hotwired/turbo@7.2.5
└─ @rails/actioncable@7.0.4
Done in 3.16s.
which: no redis-server in (/home/rudy/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/bin:/home/rudy/.asdf/installs/ruby/3.1.2/bin:/home/rudy/.asdf/shims:/home/rudy/.asdf/bin:/home/rudy/.nvm/versions/node/v19.7.0/bin:/home/rudy/.sdkman/candidates/springboot/current/bin:/home/rudy/.sdkman/candidates/maven/current/bin:/home/rudy/.sdkman/candidates/leiningen/current/bin:/home/rudy/.sdkman/candidates/kotlin/current/bin:/home/rudy/.sdkman/candidates/java/current/bin:/home/rudy/.sdkman/candidates/groovy/current/bin:/home/rudy/.sdkman/candidates/grails/current/bin:/home/rudy/.sdkman/candidates/gradle/current/bin:/home/rudy/.local/bin:/home/rudy/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin:/home/rudy/.local/share/JetBrains/Toolbox/scripts:/home/rudy/pro/Android/Sdk/tools:/home/rudy/pro/flutter/bin)
Run turbo:install:redis to switch on Redis and use it in development for turbo streams
Create controllers directory
      create  app/javascript/controllers
      create  app/javascript/controllers/index.js
      create  app/javascript/controllers/application.js
      create  app/javascript/controllers/hello_controller.js
Import Stimulus controllers
      append  app/javascript/application.js
Install Stimulus
         run  yarn add @hotwired/stimulus from "."
yarn add v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ @hotwired/stimulus@3.2.1
info All dependencies
└─ @hotwired/stimulus@3.2.1
Done in 1.29s.
       rails  css:install:bootstrap
Build into app/assets/builds
       exist  app/assets/builds
   identical  app/assets/builds/.keep
File unchanged! The supplied flag value not found!  app/assets/config/manifest.js
Stop linking stylesheets automatically
        gsub  app/assets/config/manifest.js
File unchanged! The supplied flag value not found!  .gitignore
File unchanged! The supplied flag value not found!  .gitignore
Remove app/assets/stylesheets/application.css so build output can take over
      remove  app/assets/stylesheets/application.css
Add stylesheet link tag in application layout
File unchanged! The supplied flag value not found!  app/views/layouts/application.html.erb
      append  Procfile.dev
Add bin/dev to start foreman
   identical  bin/dev
Install Bootstrap with Bootstrap Icons and Popperjs/core
      create  app/assets/stylesheets/application.bootstrap.scss
         run  yarn add sass bootstrap bootstrap-icons @popperjs/core from "."
yarn add v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 20 new dependencies.
info Direct dependencies
├─ @popperjs/core@2.11.6
├─ bootstrap-icons@1.10.3
├─ bootstrap@5.2.3
└─ sass@1.58.3
info All dependencies
├─ @popperjs/core@2.11.6
├─ anymatch@3.1.3
├─ binary-extensions@2.2.0
├─ bootstrap-icons@1.10.3
├─ bootstrap@5.2.3
├─ braces@3.0.2
├─ chokidar@3.5.3
├─ fill-range@7.0.1
├─ glob-parent@5.1.2
├─ immutable@4.2.4
├─ is-binary-path@2.1.0
├─ is-extglob@2.1.1
├─ is-glob@4.0.3
├─ is-number@7.0.0
├─ normalize-path@3.0.0
├─ picomatch@2.3.1
├─ readdirp@3.6.0
├─ sass@1.58.3
├─ source-map-js@1.0.2
└─ to-regex-range@5.0.1
Done in 5.60s.
      insert  config/initializers/assets.rb
Appending Bootstrap JavaScript import to default entry point
      append  app/javascript/application.js
Add build:css script
         run  npm pkg set scripts.build:css="sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules" from "."
         run  yarn build:css from "."
yarn run v1.22.19
$ sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules
Done in 1.57s.
unixc3t commented 1 year ago

Gemfile

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.1.2"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.4", ">= 7.0.4.2"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
gem "jsbundling-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Bundle and process CSS [https://github.com/rails/cssbundling-rails]
gem "cssbundling-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Sass to process CSS
# gem "sassc-rails"

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem "web-console"

  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
end

group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
  gem "webdrivers"
end
unixc3t commented 1 year ago

I solved it. I found the file .pnp.cjs in my home folder. I delete it

deanpcmad commented 1 year ago

This fixed it for me too, thanks!