Webpack-encore: "Error: Encore.__esModule is not a recognized property or method." after upgrade to 0.15

Created on 25 Sep 2017  路  9Comments  路  Source: symfony/webpack-encore

I've upgraded @symfony/webpack-encore to 0.15 and now I got this error:

Running webpack ...

Error: Encore.__esModule is not a recognized property or method.

  • index.js:799 Object.get
    [crm]/[@symfony]/webpack-encore/index.js:799:27

  • webpack.config.babel.js:11 _interopRequireDefault
    /var/kamil/projects/deheus/crm/webpack.config.babel.js:11:57

  • webpack.config.babel.js:9 Object.
    /var/kamil/projects/deheus/crm/webpack.config.babel.js:9:23

  • module.js:624 Module._compile
    module.js:624:30

  • node.js:144 loader
    [crm]/[babel-register]/lib/node.js:144:5

  • node.js:154 Object.require.extensions.(anonymous function) [as .js]
    [crm]/[babel-register]/lib/node.js:154:7

  • module.js:545 Module.load
    module.js:545:32

  • module.js:508 tryModuleLoad
    module.js:508:12

  • module.js:500 Function.Module._load
    module.js:500:3

  • module.js:568 Module.require
    module.js:568:17

Problematic commit: https://github.com/symfony/webpack-encore/commit/d5924814a9f6fb11fe058d89999b51bb06d623e8

All 9 comments

Hi @lewactwo,

Some questions to pinpoint the origin of this issue:

  • could you provide your webpack.config.babel.js file?
  • which command do you use to run Encore?
  • which versions of node and yarn are installed on your system?

Thanks

webpack.config.babel.js:

import Encore from '@symfony/webpack-encore';

Encore
    .setOutputPath('./public/assets/')
    .setPublicPath('/assets')
    .cleanupOutputBeforeBuild()
    .addEntry('app', './frontend/scripts/main.js')
    .addStyleEntry('global', './frontend/styles/main.scss')
    .createSharedEntry('vendor', [
        'jquery',
        'jquery-datetimepicker/jquery.datetimepicker.css'
    ])
    .enableSassLoader()
    .autoProvidejQuery()
    .enableSourceMaps(!Encore.isProduction())
    .enableVersioning()
;


const config = Encore.getWebpackConfig();

Object.assign(config, {
    resolve: {
        alias: {
            'jquery-ui/ui/widget': './vendor/jquery.ui.widget.js',
        }
    }
});

export default config;

command:
make frontend which is node_modules/.bin/encore production

node -v
v8.5.0
yarn -v
1.0.2

I'm a bit confused by the first line of your webpack.config.babel.js since Node doesn't support ES6 imports/exports yet... do you preprocess that file ?

Do you still have an error if you replace it by const Encore = require('@symfony/webpack-encore'); ?

hmm, I think this is related to the new error-catching proxy added in #150.
Such proxy is incompatible with the JS pattern of checking property existence by getting it and comparing with undefined (as this proxy is precisely throwing in this case.

@Lyrkan when the file is named webpack.config.babel.js rather than webpack.config.js, Webpack preprocesses the config file with Babel before loading it.

@weaverryan @Lyrkan I suggest whitelisting the properties accessed by the babel require wrapper (_interopRequireDefault).

I am using ES6 in webpack.config from year :) If I revert webpack-encore to 0.14 it works as expected.

How can I use ES6 in webpack.config.js?

Allow webpack.config.js to be written in ES6

@lewactwo yeah, as I said, this is related to a change we made to provide better error reporting. We should be able to fix it in the next version of Encore

Didn't know that @stof, I'll check it out more in details later but yeah it looks like the following change is enough for a basic use case (no idea if there is something else we should worry about though):

const publicApiProxy = new Proxy(publicApi, {
    get: (target, prop) => {
        if (prop === '__esModule') {
            return target[prop];
        }

        // (...)
    }
});

That's the only property they access: http://babeljs.io/repl/#?babili=false&browsers=&build=&builtIns=false&code_lz=JYWwDg9gTgLgBAMQhOAzKERwOQCMCGU2QA&debug=false&circleciRepo=&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&prettier=false&targets=&version=6.26.0

Fix merged and 0.15.1 tagged. I hope this helps! Thanks for the fix @Lyrkan and @lewactwo for the report!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Aerendir picture Aerendir  路  4Comments

zek0faws picture zek0faws  路  4Comments

heitorvrb picture heitorvrb  路  4Comments

iammichiel picture iammichiel  路  3Comments

wenmingtang picture wenmingtang  路  4Comments