Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on npm run production #67

Closed
matheusdallrosa opened this issue Dec 10, 2017 · 1 comment
Closed

Error on npm run production #67

matheusdallrosa opened this issue Dec 10, 2017 · 1 comment

Comments

@matheusdallrosa
Copy link

The provided configuration from https://github.com/postcss/postcss-loader for the postcss.config.js file is the following:

module.exports = ({ file, options, env }) => {
    return {
        parser: file.extname === '.sss' ? 'sugarss' : false,
        plugins: {
            'postcss-import': { root: file.dirname },
            'postcss-cssnext': options.cssnext ? options.cssnext : false,
            'autoprefixer': env == 'production' ? options.autoprefixer : false,
            'cssnano': env === 'production' ? options.cssnano : false
        }
    };
}

While i'm using the above configuration and i try to do npm run watch, it works pretty well, but when i try to do npm run production i receive the following errors:

 ERROR  Failed to compile with 8 errors                                                                                                                           10:10:47

 error  in ./~/toastr/toastr.less

Module build failed: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at load (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:42:38)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:66:18
    at Array.forEach (<anonymous>)
    at plugins (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:65:8)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-config/index.js:64:18
    at <anonymous>

 @ ./~/toastr/toastr.less 4:14-154
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss ./~/bootstrap-less/bootstrap/bootstrap.less ./resources/assets/less/adminlte-app.less ./~/toastr/toastr.less

 error  in ./~/bootstrap-less/bootstrap/bootstrap.less

Module build failed: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at load (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:42:38)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:66:18
    at Array.forEach (<anonymous>)
    at plugins (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:65:8)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-config/index.js:64:18
    at <anonymous>

 @ ./~/bootstrap-less/bootstrap/bootstrap.less 4:14-163
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss ./~/bootstrap-less/bootstrap/bootstrap.less ./resources/assets/less/adminlte-app.less ./~/toastr/toastr.less

 error  in ./resources/assets/less/adminlte-app.less

Module build failed: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at load (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:42:38)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:66:18
    at Array.forEach (<anonymous>)
    at plugins (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:65:8)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-config/index.js:64:18
    at <anonymous>

 @ ./resources/assets/less/adminlte-app.less 4:14-217
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss ./~/bootstrap-less/bootstrap/bootstrap.less ./resources/assets/less/adminlte-app.less ./~/toastr/toastr.less

 error  in ./resources/assets/sass/app.scss

Module build failed: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at load (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:42:38)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:66:18
    at Array.forEach (<anonymous>)
    at plugins (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:65:8)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-config/index.js:64:18
    at <anonymous>

 @ ./resources/assets/sass/app.scss 4:14-267
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss ./~/bootstrap-less/bootstrap/bootstrap.less ./resources/assets/less/adminlte-app.less ./~/toastr/toastr.less

 error  in ./resources/assets/sass/app.scss

Module build failed: ModuleBuildError: Module build failed: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at load (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:42:38)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:66:18
    at Array.forEach (<anonymous>)
    at plugins (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:65:8)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-config/index.js:64:18
    at <anonymous>
    at runLoaders (/home/matheus/Repositorios/fidelidade-online/node_modules/webpack/lib/NormalModule.js:192:19)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:364:11
    at /home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:230:18
    at context.callback (/home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at Promise.resolve.then.then.catch (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-loader/lib/index.js:189:71)
    at <anonymous>

 error  in ./~/bootstrap-less/bootstrap/bootstrap.less

Module build failed: ModuleBuildError: Module build failed: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at load (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:42:38)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:66:18
    at Array.forEach (<anonymous>)
    at plugins (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:65:8)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-config/index.js:64:18
    at <anonymous>
    at runLoaders (/home/matheus/Repositorios/fidelidade-online/node_modules/webpack/lib/NormalModule.js:192:19)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:364:11
    at /home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:230:18
    at context.callback (/home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at Promise.resolve.then.then.catch (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-loader/lib/index.js:189:71)
    at <anonymous>

 error  in ./resources/assets/less/adminlte-app.less

Module build failed: ModuleBuildError: Module build failed: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at load (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:42:38)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:66:18
    at Array.forEach (<anonymous>)
    at plugins (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:65:8)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-config/index.js:64:18
    at <anonymous>
    at runLoaders (/home/matheus/Repositorios/fidelidade-online/node_modules/webpack/lib/NormalModule.js:192:19)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:364:11
    at /home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:230:18
    at context.callback (/home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at Promise.resolve.then.then.catch (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-loader/lib/index.js:189:71)
    at <anonymous>

 error  in ./~/toastr/toastr.less

Module build failed: ModuleBuildError: Module build failed: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at load (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:42:38)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:66:18
    at Array.forEach (<anonymous>)
    at plugins (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:65:8)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-config/index.js:64:18
    at <anonymous>
    at runLoaders (/home/matheus/Repositorios/fidelidade-online/node_modules/webpack/lib/NormalModule.js:192:19)
    at /home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:364:11
    at /home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:230:18
    at context.callback (/home/matheus/Repositorios/fidelidade-online/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at Promise.resolve.then.then.catch (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-loader/lib/index.js:189:71)
    at <anonymous>

                                      Asset     Size  Chunks                    Chunk Names
            /js/app.9be25d8d3599f636ed1a.js   352 kB       0  [emitted]  [big]  /js/app
    /js/app-landing.4e4cffbf4f5d977096ec.js   216 kB       1  [emitted]         /js/app-landing
        /js/app.9be25d8d3599f636ed1a.js.map   362 kB       0  [emitted]         /js/app
/js/app-landing.4e4cffbf4f5d977096ec.js.map   221 kB       1  [emitted]         /js/app-landing
                          mix-manifest.json  4.63 kB          [emitted]         
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ production: `cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the @ production script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/matheus/.npm/_logs/2017-12-08T12_10_48_182Z-debug.log

I looked at the file: /node_modules/postcss-load-plugins/lib/plugins.js
And i noticed that on the following if statement:
if (options === null || Object.keys(options).length === 0)

Its being tested only if the options object is null, if the object is not null it tries to
look at the keys of the object, but i believe that its being forgotten the case when the options object is undefined.

I changed my postcss.config.js to the following code:

module.exports = ({ file, options, env }) => {
    env = env || {};
    file = file || {};
    options = options || {};
    options.cssnext = options.cssnext || null;
    options.autoprefixer = options.autoprefixer || null;
    options.cssnano = options.cssnano || null;
    return {
        parser: file.extname === '.sss' ? 'sugarss' : false,
        plugins: {
            'postcss-import': { root: file.dirname },
            'postcss-cssnext': options.cssnext ? options.cssnext : false,
            'autoprefixer': env == 'production' ? options.autoprefixer : false,
            'cssnano': env === 'production' ? options.cssnano : false
        }
    };
}

And now both npm run watch and npm run production are working.
I don't know if any environment configuration could be useful, if someone need some just ask for it and i'll give it.
Thanks for your attention.

@michael-ciniawsky
Copy link
Owner

michael-ciniawsky commented Jul 13, 2018

Since this repo will be archived soon, I'm closing in favor of postcss-load-config #154. I copied the needed bits and will fix it asap. Thx for reporting 🎉

@michael-ciniawsky michael-ciniawsky removed this from the v3.0.0 milestone Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants