-1

Hello I try to install sylius BootstrapTheme for my project and I have little problem when i try to install this. If need more code or code of other files for find the problem talk me

/themes/BootstrapTheme/webpack.config.js

const Encore = require('@symfony/webpack-encore');

Encore
  .setOutputPath('public/bootstrap-theme')
  .setPublicPath('/bootstrap-theme')
  .addEntry('app', './themes/BootstrapTheme/assets/app.js')
  .disableSingleRuntimeChunk()
  .cleanupOutputBeforeBuild()
  .enableSassLoader()
  .enableSourceMaps(!Encore.isProduction())
  .enableVersioning(Encore.isProduction());

const config = Encore.getWebpackConfig();
config.name = 'bootstrapTheme';

module.exports = config;

webpack.config.js

const Encore = require('@symfony/webpack-encore');
const bootstrapTheme = require('./themes/BootstrapTheme/webpack.config');
module.exports = [bootstrapTheme];
// 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')
    // 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.
     */
    .addEntry('app', './assets/js/app.js')
    //.addEntry('page1', './assets/js/page1.js')
    //.addEntry('page2', './assets/js/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
    .configureBabel(() => {}, {
        useBuiltIns: 'usage',
        corejs: 3
    })

    // enables Sass/SCSS support
    //.enableSassLoader()

    // 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/js/admin.js')
;

module.exports = Encore.getWebpackConfig();

but when I when I run yarn encore production I have this error :

Duplicate name "app" passed to addEntry(): entries must be unique.

what I can do for leave this?

tereško
  • 56,151
  • 24
  • 92
  • 147
Den Kot
  • 41
  • 2
  • 10

1 Answers1

0

The error message is clear Duplicate name "app" passed to addEntry(): entries must be unique..

In your /themes/BootstrapTheme/webpack.config.js you have:

.addEntry('app', './themes/BootstrapTheme/assets/app.js')

And, in your webpack.config.js:

.addEntry('app', './assets/js/app.js')

I'm far from being an expert in Webpack but I believe you could delete the second one, as now you are using BootstrapTheme's one. If you need both the scripts, you could change the name of the entry in your webpack.config.js to something else, like:

.addEntry('someName', './assets/js/app.js')

Then you add your new tag to the twig file:

{% block javascripts %}
    {{ encore_entry_script_tags('app') }}
    {{ encore_entry_script_tags('someName') }}
//the rest of your js code, if you have
{% endblock %}

Caconde
  • 2,969
  • 7
  • 24
  • 27
  • Try to just remove the line `.addEntry('app', './assets/js/app.js')` from your `webpack.config.js`, keeping the one that came with BoostrapTheme. If nothing breaks, the job is done. – Caconde Jul 27 '19 at 14:02
  • I edited my answer with an example of what you can try next – Caconde Jul 28 '19 at 15:13