无法使用d3部署Rails 6应用。在本地运行,但是Heroku构建中断:ModuleNotFoundError:未找到模块:错误:无法解析'd3'

问题描述 投票:0回答:1

我在模块中这样导入d3:

import * as d3 from "d3"

并且该应用程序可以在localhost上正常工作,并生成所需的图表。但是当我推送到heroku时,预编译失败。

我还没有接触过任何webpack或webpacker配置,一切都与Rails提供的一样。

除了通过在import语句中提供到d3的直接路径来解决该情况以外,我对这种情况没有太多提及。我试过了,但是错误没有改变。

有关如何解决此问题并确保成功部署到Heroku的任何想法?

谢谢!

package.json

{
  "name": "the_app",
  "private": true,
  "dependencies": {
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "4.2.2",
    "turbolinks": "^5.2.0"
  },
  "version": "0.1.0",
  "devDependencies": {
    "d3": "^5.16.0",
    "webpack-dev-server": "^3.10.3"
  }
}

错误

remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        yarn install v1.16.0
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        info [email protected]: The platform "linux" is incompatible with this module.
remote:        info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [3/4] Linking dependencies...
remote:        warning " > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
remote:        warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^4.0.0".
remote:        [4/4] Building fresh packages...
remote:        Done in 23.83s.
remote:        yarn install v1.16.0
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        info [email protected]: The platform "linux" is incompatible with this module.
remote:        info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [3/4] Linking dependencies...
remote:        warning " > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
remote:        warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^4.0.0".
remote:        [4/4] Building fresh packages...
remote:        Done in 4.98s.
remote:        I, [2020-05-28T00:58:16.236509 #435]  INFO -- : Writing /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/public/assets/application-e9ef9b65582d84e0bcb1825908e96a08d055278ce584c687748a7dbd3a739747.css
remote:        I, [2020-05-28T00:58:16.236817 #435]  INFO -- : Writing /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/public/assets/application-e9ef9b65582d84e0bcb1825908e96a08d055278ce584c687748a7dbd3a739747.css.gz
remote:        I, [2020-05-28T00:58:16.237059 #435]  INFO -- : Writing /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/public/assets/main-e9ef9b65582d84e0bcb1825908e96a08d055278ce584c687748a7dbd3a739747.css
remote:        I, [2020-05-28T00:58:16.237229 #435]  INFO -- : Writing /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/public/assets/main-e9ef9b65582d84e0bcb1825908e96a08d055278ce584c687748a7dbd3a739747.css.gz
remote:        Compiling...
remote:        Compilation failed:
remote:        ModuleNotFoundError: Module not found: Error: Can't resolve 'd3' in '/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/modules'
remote:            at factory.create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/lib/Compilation.js:925:10)
remote:            at factory (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/lib/NormalModuleFactory.js:401:22)
remote:            at resolver (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/lib/NormalModuleFactory.js:130:21)
remote:            at asyncLib.parallel (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/lib/NormalModuleFactory.js:224:22)
remote:            at /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/neo-async/async.js:2830:7
remote:            at /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/neo-async/async.js:6877:13
remote:            at normalResolver.resolve (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/lib/NormalModuleFactory.js:214:25)
remote:            at doResolve (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:213:14)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn0 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
remote:            at resolver.doResolve (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn0 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn0 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
remote:            at resolver.doResolve (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn41 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:28:1)
remote:            at resolver.doResolve (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/ModuleKindPlugin.js:30:40)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn0 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn1 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
remote:            at args (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/forEachBail.js:30:14)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn0 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
remote:            at resolver.doResolve (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn0 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn0 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
remote:            at resolver.doResolve (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn42 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
remote:            at hook.callAsync (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
remote:            at _fn0 (eval at create (/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
remote:        resolve 'd3' in '/tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/modules'
remote:          Parsed request is a module
remote:          using description file: /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/package.json (relative path: ./app/javascript/modules)
remote:            Field 'browser' doesn't contain a valid alias configuration
remote:            resolve as module
remote:              looking for modules in /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript
remote:                using description file: /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/package.json (relative path: ./app/javascript)
remote:                  Field 'browser' doesn't contain a valid alias configuration
remote:                  using description file: /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/package.json (relative path: ./app/javascript/d3)
remote:                    no extension
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3 doesn't exist
remote:                    .mjs
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.mjs doesn't exist
remote:                    .js
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.js doesn't exist
remote:                    .sass
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.sass doesn't exist
remote:                    .scss
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.scss doesn't exist
remote:                    .css
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.css doesn't exist
remote:                    .module.sass
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.module.sass doesn't exist
remote:                    .module.scss
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.module.scss doesn't exist
remote:                    .module.css
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.module.css doesn't exist
remote:                    .png
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.png doesn't exist
remote:                    .svg
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.svg doesn't exist
remote:                    .gif
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.gif doesn't exist
remote:                    .jpeg
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.jpeg doesn't exist
remote:                    .jpg
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3.jpg doesn't exist
remote:                    as directory
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/d3 doesn't exist
remote:              /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/modules/node_modules doesn't exist or is not a directory
remote:              /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/javascript/node_modules doesn't exist or is not a directory
remote:              /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/app/node_modules doesn't exist or is not a directory
remote:              /tmp/node_modules doesn't exist or is not a directory
remote:              /node_modules doesn't exist or is not a directory
remote:              looking for modules in /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules
remote:                using description file: /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/package.json (relative path: ./node_modules)
remote:                  Field 'browser' doesn't contain a valid alias configuration
remote:                  using description file: /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/package.json (relative path: ./node_modules/d3)
remote:                    no extension
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3 doesn't exist
remote:                    .mjs
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.mjs doesn't exist
remote:                    .js
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.js doesn't exist
remote:                    .sass
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.sass doesn't exist
remote:                    .scss
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.scss doesn't exist
remote:                    .css
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.css doesn't exist
remote:                    .module.sass
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.module.sass doesn't exist
remote:                    .module.scss
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.module.scss doesn't exist
remote:                    .module.css
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.module.css doesn't exist
remote:                    .png
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.png doesn't exist
remote:                    .svg
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.svg doesn't exist
remote:                    .gif
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.gif doesn't exist
remote:                    .jpeg
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.jpeg doesn't exist
remote:                    .jpg
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3.jpg doesn't exist
remote:                    as directory
remote:                      /tmp/build_ee117d42c87cfaf2c16b46c6bf931917/node_modules/d3 doesn't exist
remote:
remote:
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to the-app
d3.js heroku assets ruby-on-rails-6 webpacker
1个回答
1
投票

问题是,我已将d3安装为仅开发人员依赖项,如package.json文件所示。

yarn add d3

解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.