rails / webpacker

Use Webpack to manage app-like JavaScript modules in Rails
MIT License
5.31k stars 1.47k forks source link

Error running rake webpacker:compile #1234

Closed wpolicarpo closed 6 years ago

wpolicarpo commented 6 years ago

Scenario

I have a Rails 5.1 app (migrated from Rails 4.1) and now I'm configuring webpacker + vue.

I've added gem 'webpacker' to Gemfile and ran rake webpacker:install. All dependencies where successfully installed, but I'm unable to run rake webpacker:compile.

I have already removed all dependencies and tried to compile just with webpacker dependencies with no success. I also tried to remove yarn-offline-mirror config. webpacker.yml is the default one generated by rake task.

Output from rake webpacker:compile

$ rake webpacker:compile
Webpacker is installed 🎉 🍰
Using /app/config/webpacker.yml file for setting up webpack paths
Compiling…
Compilation failed:

module.js:557
    throw err;
    ^

Error: Cannot find module './vendor/parse'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/app/node_modules/parse-json/index.js:3:16)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)

Relevant gems

source 'https://rubygems.org'

ruby '2.5.0'

gem 'rails', '5.1.3'
gem 'bundler'
gem 'coffee-rails'
gem 'jbuilder'
gem 'sass-rails'
gem 'turbolinks'
gem 'uglifier', '>= 1.3.0'
gem 'bootstrap-sass', '~> 3.3.6'
gem 'webpacker', '3.2.1'

env

$ node -v # v9.4.0
$ yarn -v # 1.3.2
$ ruby -v # ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
$ rails -v # Rails 5.1.3

.yarnrc

# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1

yarn-offline-mirror "./vendor/yarn"
yarn-offline-mirror-pruning true

package.json

{
  "name": "app",
  "private": true,
  "dependencies": {
    "@rails/webpacker": "^3.2.1",
    "classnames": "^2.2.5",
    "datatables.net": "^1.10.16",
    "datatables.net-bs": "^1.10.16",
    "diffhtml": "^1.0.0-beta.9",
    "es6-shim": "^0.35.3",
    "fecha": "^2.3.1",
    "jquery-ui-dist": "^1.12.1",
    "jquery.json-viewer": "^1.1.0",
    "js-sha512": "^0.5.0",
    "nprogress": "^0.2.0",
    "path-browser": "^2.2.1"
  },
  "devDependencies": {
    "webpack-dev-server": "^2.11.1"
  }
}

webpacker.yml

# Note: You must restart bin/webpack-dev-server for changes to take effect

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_output_path: packs
  cache_path: tmp/cache/webpacker

  # Additional paths webpack should lookup modules
  # ['app/assets', 'engine/foo/app/assets']
  resolved_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  extensions:
    - .js
    - .sass
    - .scss
    - .css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: /node_modules/

test:
  <<: *default
  compile: true

  # Compile test packs to a separate directory
  public_output_path: packs-test

production:
  <<: *default

  # Production depends on precompilation of packs prior to booting for performance.
  compile: false

  # Cache manifest.json for performance
  cache_manifest: true
wpolicarpo commented 6 years ago

Found a yarnclean config removing some undesired files from build that was causing this issue. All good with webpacker.