0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Webpacker動かない

Last updated at Posted at 2022-08-18

rails sしてプレビューすると

Webpacker::Manifest::MissingEntryError in Homes#top
Showing /home/ec2-user/environment/Rails6_ojt_test/app/views/layouts/application.html.erb where line #9 raised:

Webpacker can't find application.js in /home/ec2-user/environment/Rails6_ojt_test/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
   unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}

これはrails webpacker:installrails webpacker:cpmpileで解決しようとする。compileすると

rails webpacker:compile
Compiling...
Compilation failed:
yarn run v1.22.19
info If you think this is a bug, please open a bug report with the information provided in "/home/ec2-user/environment/Rails6_ojt_test/yarn-error.log".
yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

error An unexpected error occurred: "/home/ec2-user/environment/Rails6_ojt_test/package.json: Unexpected string in JSON at position 496".                                   error An unexpected error occurred: "/home/ec2-user/environment/Rails6_ojt_test/package.json: Unexpected string in JSON at position 496".

package.jsonを消したら

Compiling...
Compilation failed:
yarn run v1.22.19
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


warning package.json: No license field
warning package.json: No license field
error Command "webpack" not found.

環境構築を行い、再びrails webpacker:installrails webpacker:compile、コンパイルすると

Compiling...
Compilation failed:
warning package.json: No license field
ModuleNotFoundError: Module not found: Error: Can't resolve 'turbolinks' in '/home/ec2-user/environment/Rails6_ojt_test/app/javascript/packs'
    at /home/ec2-user/node_modules/webpack/lib/Compilation.js:925:10
    at /home/ec2-user/node_modules/webpack/lib/NormalModuleFactory.js:401:22
    at /home/ec2-user/node_modules/webpack/lib/NormalModuleFactory.js:130:21
    at /home/ec2-user/node_modules/webpack/lib/NormalModuleFactory.js:224:22
    at /home/ec2-user/node_modules/neo-async/async.js:2830:7
    at /home/ec2-user/node_modules/neo-async/async.js:6877:13
    at /home/ec2-user/node_modules/webpack/lib/NormalModuleFactory.js:214:25
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:213:14
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /home/ec2-user/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
    at /home/ec2-user/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:43:1)
    at /home/ec2-user/node_modules/enhanced-resolve/lib/ModuleKindPlugin.js:30:40
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
    at /home/ec2-user/node_modules/enhanced-resolve/lib/forEachBail.js:30:14
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /home/ec2-user/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
    at /home/ec2-user/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
    at /home/ec2-user/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
    at /home/ec2-user/node_modules/enhanced-resolve/lib/RootPlugin.js:37:38
    at _next42 (eval at create (/home/ec2-user/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:8:1)
resolve 'turbolinks' in '/home/ec2-user/environment/Rails6_ojt_test/app/javascript/packs'
  Parsed request is a module
  using description file: /home/ec2-user/package.json (relative path: ./environment/Rails6_ojt_test/app/javascript/packs)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /home/ec2-user/environment/Rails6_ojt_test/app/javascript
        using description file: /home/ec2-user/package.json (relative path: ./environment/Rails6_ojt_test/app/javascript)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/ec2-user/package.json (relative path: ./environment/Rails6_ojt_test/app/javascript/turbolinks)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.js doesn't exist
            .sass
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.sass doesn't exist
            .scss
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.scss doesn't exist
            .css
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.css doesn't exist
            .module.sass
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.module.sass doesn't exist
            .module.scss
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.module.scss doesn't exist
            .module.css
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.module.css doesn't exist
            .png
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.png doesn't exist
            .svg
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.svg doesn't exist
            .gif
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.gif doesn't exist
            .jpeg
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.jpeg doesn't exist
            .jpg
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks.jpg doesn't exist
            as directory
              /home/ec2-user/environment/Rails6_ojt_test/app/javascript/turbolinks doesn't exist
      /home/ec2-user/environment/Rails6_ojt_test/app/javascript/packs/node_modules doesn't exist or is not a directory
      /home/ec2-user/environment/Rails6_ojt_test/app/javascript/node_modules doesn't exist or is not a directory
      /home/ec2-user/environment/Rails6_ojt_test/app/node_modules doesn't exist or is not a directory
      /home/ec2-user/environment/Rails6_ojt_test/node_modules doesn't exist or is not a directory
      /home/ec2-user/environment/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /home/ec2-user/node_modules
        using description file: /home/ec2-user/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/ec2-user/package.json (relative path: ./node_modules/turbolinks)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.js doesn't exist
            .sass
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.sass doesn't exist
            .scss
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.scss doesn't exist
            .css
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.css doesn't exist
            .module.sass
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.module.sass doesn't exist
            .module.scss
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.module.scss doesn't exist
            .module.css
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.module.css doesn't exist
            .png
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.png doesn't exist
            .svg
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.svg doesn't exist
            .gif
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.gif doesn't exist
            .jpeg
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.jpeg doesn't exist
            .jpg
              Field 'browser' doesn't contain a valid alias configuration
              /home/ec2-user/node_modules/turbolinks.jpg doesn't exist
            as directory
              /home/ec2-user/node_modules/turbolinks doesn't exist

結局階層を間違えていて、~/environmentで動かしてしまっていた。正しくは~/environment/Rails6_ojt_testで動かすべきだった
階層を変えてからrails webpacker:installrails webpacker:compileで動くようになった。階層に注意する、、

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?