Webpack-encore: Example giving in documentation does not work on windows

Created on 14 Jun 2017  路  18Comments  路  Source: symfony/webpack-encore

When following the first example in documentation you will end up with this error on windows

Error: Cannot determine how to prefix the keys in manifest.json. Call Encore.setManifestKeyPrefix() to choose what path (e.g. build/) to use when building your manifest keys. This is caused by setOutpu
tPath() and setPublicPath() containing paths that don't seem compatible.

This is reproduce able by creating an empty directory and following:

  1. execute $ yarn add @symfony/webpack-encore --dev
  2. create webpack.config.js file with contents found on http://symfony.com/doc/current/frontend/encore/simple-example.html
  3. creating assets/js/main.js & assets/css/global.scss
  4. execute ./node_modules/.bin/encore dev

Most helpful comment

Temporary fix for Windows environment:

Encore
// directory where all compiled assets will be stored
    .setOutputPath('web/build')

    // Windows??? <---------------------------
    .setManifestKeyPrefix('/build')

    // what's the public path to this directory (relative to your project's document root dir)
    .setPublicPath('/build')

    // empty the outputPath dir before each build
    .cleanupOutputBeforeBuild()
    // ...

At least this one is worked for me. @DaRamirezSoto Can you confirm, that this workaround is ok?

All 18 comments

This makes sense - some of the path comparisons are certainly choking on the \ paths from Windows. We need to setup appveyor (it should be activated, but we don't have any config for it yet). That should show us the errors and they'll be easy to fix :).

No way to use Webpack Encore on windows yet then ?

@Alestaan Currently no.
I have tried some workaround but issue might be more deeper than initially thought off.
Majority of the functions with in encore assume '/' as separator in paths.
Which breaks the functionality on windows.

@weaverryan we should enable CI using AppVeyor too, to have a Windows CI 馃槃

@stof & @weaverryan
I create a pull request with configuration file for AppVeyor.
I few questions to make it better.

  1. Should we use cache for node_modules ? ( I'm not sure if this will bring conflicts when switching version and platform)
  2. Should we run tests against multiple managersr like choco yarn and npm ? ( currently only npm is used to test )
  3. Should we include travis:lint in all version or only on 7 as defined in travis config file
  4. How to deal with build numbers ?

Should we run tests against multiple managersr like choco yarn and npm ? ( currently only npm is used to test

not worth it. We are not meant to test package managers themselves

How to deal with build numbers ?

What do you mean ?

@stof
You can defined how build numbers wilt be formatted. I am not sure if we use for something but if not.
I leave it as it is.

Temporary fix for Windows environment:

Encore
// directory where all compiled assets will be stored
    .setOutputPath('web/build')

    // Windows??? <---------------------------
    .setManifestKeyPrefix('/build')

    // what's the public path to this directory (relative to your project's document root dir)
    .setPublicPath('/build')

    // empty the outputPath dir before each build
    .cleanupOutputBeforeBuild()
    // ...

At least this one is worked for me. @DaRamirezSoto Can you confirm, that this workaround is ok?

@vdjagilev confirmed your solutions works on windows

well .. encore has some issues on windows ( found out today .. ) and in docker it has a few problems.. couldn't install it at all.

@vdjagilev the setManifestKeyPrefix() works on windows tested it earlier.

Despite the workaround working on windows, are you having an issue with the following command ?

yarn run encore dev --watch

It's only compiling but not watching so i'm a bit confused here.

@Alestaan Hi,

I am executing this command:

node_modules\.bin\encore dev

@vdjagilev Hi,

Oh i see now ... so i shouldn't use the yarn run encore dev command right ?

But shouldn't the yarn run command be supported for the watch ? (i'm just asking, i'm curious about it)

Anyway, thanks !!

@Alestaan Try npm instead of yarn

.\node_modules\.bin\encore dev --watch is what i run and work ok with no problems from powershell not from cmd and also i installed nvm using scoop.

@Alestaan here a small tip
You can add a script section to your package.json like so ( if already existing add to it ):

"scripts": {
    "assets:dev": "encore dev --watch",
    "assets:build": "encore production"
  },

This will allow you do

  • npm run command when using npm
  • yarn run command when using yarn

Where command can be any of the commands like assets:dev or assets:build
You can use your own naming convention of course.

Windows support fixed! I've also opened an docs issue to show the correct executable path on Windows: https://github.com/symfony/symfony-docs/issues/8073. Creating the scripts section like @DaRamirezSoto is an even better solution (than running the longer command each time).

Was this page helpful?
0 / 5 - 0 ratings