简体   繁体   English

Symfony/encore 在没有 devDependencies 的情况下无法编译

[英]Symfony/encore does not compile without devDependencies

I use Symfony5 with encore, everything was fine until I tried to deploy to production.我将 Symfony5 与 encore 一起使用,在我尝试部署到生产之前一切都很好。 Run npm install --production to install dependencies.运行 npm install --production 以安装依赖项。 Run npm run build --prod to compile.运行 npm 运行 build --prod 进行编译。

Does @symfony/encore-webpack really have to be devDependency? @symfony/encore-webpack 真的必须是 devDependency 吗? I tried to move @symfony/encore-webpack from devDependencies to dependencies, but then I got an error telling that I need to install node-sass and sass-loader though they are in devDependencies (which as I understand definately should be there).我试图将 @symfony/encore-webpack 从 devDependencies 移动到依赖项,但随后我收到一个错误消息,提示我需要安装 node-sass 和 sass-loader,尽管它们位于 devDependencies 中(据我所知,它们肯定应该在那里)。

This is error log:这是错误日志:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/root/.nvm/versions/node/v14.15.5/bin/node',
1 verbose cli   '/root/.nvm/versions/node/v14.15.5/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build'
1 verbose cli ]
2 info using npm@6.14.11
3 info using node@v14.15.5
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle @~prebuild: @
6 info lifecycle @~build: @
7 verbose lifecycle @~build: unsafe-perm in lifecycle true
8 verbose lifecycle @~build: PATH: /root/.nvm/versions/node/v14.15.5/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/var/www/app/node_modules/.bin:/root/.nvm/versions/node/v14.15.5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
9 verbose lifecycle @~build: CWD: /var/www/app
10 silly lifecycle @~build: Args: [ '-c', 'encore production --progress' ]
11 info lifecycle @~build: Failed to exec build script
12 verbose stack Error: @ build: `encore production --progress`
12 verbose stack spawn ENOENT
12 verbose stack     at ChildProcess.<anonymous> (/root/.nvm/versions/node/v14.15.5/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
12 verbose stack     at ChildProcess.emit (events.js:315:20)
12 verbose stack     at maybeClose (internal/child_process.js:1048:16)
12 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
13 verbose pkgid @
14 verbose cwd /var/www/app
15 verbose Linux 5.4.0-72-generic
16 verbose argv "/root/.nvm/versions/node/v14.15.5/bin/node" "/root/.nvm/versions/node/v14.15.5/bin/npm" "run" "build"
17 verbose node v14.15.5
18 verbose npm  v6.14.11
19 error code ELIFECYCLE
20 error syscall spawn
21 error file sh
22 error errno ENOENT
23 error @ build: `encore production --progress`
23 error spawn ENOENT
24 error Failed at the @ build script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]`

This is my package.json:这是我的 package.json:

{
    "devDependencies": {
        "@babel/core": "^7.12.10",
        "@symfony/webpack-encore": "^0.31.0",
        "@vue/cli-plugin-babel": "^4.5.9",
        "@vue/cli-plugin-e2e-nightwatch": "^4.5.9",
        "@vue/cli-plugin-eslint": "^4.5.9",
        "@vue/cli-plugin-unit-jest": "^4.5.9",
        "@vue/cli-service": "^4.5.9",
        "@vue/test-utils": "^1.1.2",
        "auto-changelog": "^2.2.1",
        "babel-eslint": "~10.1.0",
        "babel-jest": "~26.3.0",
        "bootstrap": "^4.5.3",
        "chromedriver": "^87.0.4",
        "core-js": "^3.8.2",
        "jquery": "^3.5.1",
        "node-sass": "~4.14.1",
        "npm-run-all": "~4.1.5",
        "popper.js": "^1.16.1",
        "regenerator-runtime": "^0.13.2",
        "resolve-url-loader": "^3.1.2",
        "sass-loader": "^9.0.3",
        "vue-template-compiler": "^2.6.12",
        "webpack-notifier": "^1.6.0"
    },
    "license": "UNLICENSED",
    "private": true,
    "scripts": {
        "dev-server": "encore dev-server",
        "dev": "encore dev",
        "watch": "encore dev --watch",
        "build": "encore production --progress"
    },
    "dependencies": {
        "@coreui/coreui": "^3.4.0",
        "@coreui/icons": "^2.0.0-rc.0",
        "@coreui/utils": "^1.3.1",
        "@coreui/vue": "^3.2.7",
        "@coreui/vue-chartjs": "^1.0.6",
        "@fortawesome/fontawesome-free": "^5.15.2",
        "@fortawesome/free-solid-svg-icons": "^5.15.2",
        "@fortawesome/vue-fontawesome": "^2.0.2",
        "@symfony/webpack-encore": "^0.31.0",
        "@tinymce/tinymce-vue": "^3.2.8",
        "axios": "^0.21.1",
        "bootstrap-vue": "^2.21.2",
        "moment": "^2.29.1",
        "tinymce": "^5.7.0",
        "vue": "^2.6.12",
        "vue-bootstrap-datetimepicker": "^5.0.1",
        "vue-loader": "^15.9.6",
        "vue-router": "^3.4.9",
        "vue-select": "^3.11.2",
        "vuex": "^3.6.0"
    }
}

webpack.config.js: webpack.config.js:

var Encore = require('@symfony/webpack-encore');
var path = require('path');
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
    Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}

Encore
    // directory where compiled assets will be stored
    .setOutputPath('public/build/')
    // public path used by the web server to access the output path
    .setPublicPath('/build')
    .copyFiles([
        {
            from: './assets/images',
            to: 'images/[name].[ext]',
            pattern: /\.(png|jpg|jpeg|svg)$/
        }
    ])

    // only needed for CDN's or sub-directory deploy
    //.setManifestKeyPrefix('build/')

    /*
     * ENTRY CONFIG
     *
     * Add 1 entry for each "page" of your app
     * (including one that's included on every page - e.g. "app")
     *
     * Each entry will result in one JavaScript file (e.g. app.js)
     * and one CSS file (e.g. app.css) if your JavaScript imports CSS.
     */
    .enableVueLoader(() => {}, { runtimeCompilerBuild: false })
    .addEntry('app', './assets/app.js')
    .addEntry('contracts', './assets/vue/contracts.js')
    .addEntry('admin', './assets/vue/admin.js')
    //.addEntry('page2', './assets/page2.js')
    // When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
    .splitEntryChunks()

    // will require an extra script tag for runtime.js
    // but, you probably want this, unless you're building a single-page app
    .enableSingleRuntimeChunk()

    /*
     * FEATURE CONFIG
     *
     * Enable & configure other features below. For a full
     * list of features, see:
     * https://symfony.com/doc/current/frontend.html#adding-more-features
     */
    .cleanupOutputBeforeBuild()
    .enableBuildNotifications()
    .enableSourceMaps(!Encore.isProduction())
    // enables hashed filenames (e.g. app.abc123.css)
    .enableVersioning(Encore.isProduction())

    // enables @babel/preset-env polyfills
    .configureBabelPresetEnv((config) => {
        config.useBuiltIns = 'usage';
        config.corejs = 3;
    })

    // enables Sass/SCSS support
    .enableSassLoader(function(options) {}, {
        resolveUrlLoader: true
    })

    // uncomment if you use TypeScript
    //.enableTypeScriptLoader()

    // uncomment to get integrity="..." attributes on your script & link tags
    // requires WebpackEncoreBundle 1.4 or higher
    //.enableIntegrityHashes(Encore.isProduction())

    // uncomment if you're having problems with a jQuery plugin
    .autoProvidejQuery()

    // uncomment if you use API Platform Admin (composer req api-admin)
    //.enableReactPreset()
    //.addEntry('admin', './assets/admin.js')
;


let config = Encore.getWebpackConfig();
// function resolve (dir) {
//     return path.join(__dirname, '..', dir)
// }

config.resolve.alias = {
    'local': path.resolve(__dirname, './assets/vue'),
    '@': path.resolve(__dirname, './assets/vue/admin/src')
};

module.exports = config;

I guess that this did it for me:我想这对我来说是这样的:

rm -fr node_modules/ && npm install --force

After run scripts resumed to work.运行脚本后恢复工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM