Error when running Sage build:production

Hi there,

Encountering an issue when trying to run the webpack build:production task as per described here: https://github.com/roots/sage/tree/sage-9

Both the build and watch tasks work fine, but the build:production throws an error in emitpath.js.

I believe it’s trying to supply an object instead of a string as an argument. Tested on a clean bedrock+sage install, all the latest versions of composer, npm, and node installed.

Terminal Output

npm run build:production

> sage@9.0.0 build:production /Users/****/Sites/sandbox/bedrock/web/app/themes/sage
> webpack -p --progress --release

clean-webpack-plugin: /Users/****/Sites/sandbox/bedrock/web/app/themes/sage/dist has been removed.
 90% optimize assets        
Starting to optimize CSS...
Processing styles/main_e286f6c47431638eb560.css...
Processed styles/main_e286f6c47431638eb560.css, before: 140014, after: 139623, ratio: 99.72%
 95% emitpath.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received { js: 'scripts/main_e286f6c47431638eb560.js',
  css: 'styles/main_e286f6c47431638eb560.css' }
    at assertPath (path.js:7:11)
    at Object.extname (path.js:1433:5)
    at Object.assetsPluginProcessOutput [as processOutput] (/Users/****/Sites/sandbox/bedrock/web/app/themes/sage/webpack.config.js:47:16)
    at ReadFileContext.callback (/Users/****/Sites/sandbox/bedrock/web/app/themes/sage/node_modules/assets-webpack-plugin/lib/output/createOutputWriter.js:43:30)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:359:13)

npm ERR! Darwin 15.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build:production"
npm ERR! node v6.2.2
npm ERR! npm  v3.10.2
npm ERR! code ELIFECYCLE
npm ERR! sage@9.0.0 build:production: `webpack -p --progress --release`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the sage@9.0.0 build:production script 'webpack -p --progress --release'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the sage package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack -p --progress --release
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs sage
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls sage
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/****/Sites/sandbox/bedrock/web/app/themes/sage/npm-debug.log

npm-debug.log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build:production' ]
2 info using npm@3.10.2
3 info using node@v6.2.2
4 verbose run-script [ 'prebuild:production',
4 verbose run-script   'build:production',
4 verbose run-script   'postbuild:production' ]
5 info lifecycle sage@9.0.0~prebuild:production: sage@9.0.0
6 silly lifecycle sage@9.0.0~prebuild:production: no script for prebuild:production, continuing
7 info lifecycle sage@9.0.0~build:production: sage@9.0.0
8 verbose lifecycle sage@9.0.0~build:production: unsafe-perm in lifecycle true
9 verbose lifecycle sage@9.0.0~build:production: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/****/Sites/sandbox/bedrock/web/app/themes/sage/node_modules/.bin:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
10 verbose lifecycle sage@9.0.0~build:production: CWD: /Users/****/Sites/sandbox/bedrock/web/app/themes/sage
11 silly lifecycle sage@9.0.0~build:production: Args: [ '-c', 'webpack -p --progress --release' ]
12 silly lifecycle sage@9.0.0~build:production: Returned: code: 1  signal: null
13 info lifecycle sage@9.0.0~build:production: Failed to exec build:production script
14 verbose stack Error: sage@9.0.0 build:production: `webpack -p --progress --release`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:242:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:852:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid sage@9.0.0
16 verbose cwd /Users/****/Sites/sandbox/bedrock/web/app/themes/sage
17 error Darwin 15.5.0
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build:production"
19 error node v6.2.2
20 error npm  v3.10.2
21 error code ELIFECYCLE
22 error sage@9.0.0 build:production: `webpack -p --progress --release`
22 error Exit status 1
23 error Failed at the sage@9.0.0 build:production script 'webpack -p --progress --release'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the sage package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     webpack -p --progress --release
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs sage
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls sage
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

have a look here

1 Like

Thanks! dani-z’s solution of changing path.extname() to path.format() in webpack.config.js worked.

1 Like

Thanks for this fix!

Hi guys,

I am experiencing the same issue with Sage 9 ; no solution so far.

Any idea?

Thanks.

We’re going to need a little more information than that. What have you tried?

Hi,

Thanks for your answer.

So I ran yarn run build:production and I got the following error:

$ webpack --progress -p --config resources/assets/build/webpack.config.js
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.`````

Thanks.

Is this a vanilla copy of Sage, straight out of the box, or have you customized it at all before running yarn build:production ?

Well, I made some changes (added npm packages mainly).
thanks.

I recommend removing the packages one by one and seeing which one causes it to break or un-break when added/removed. This will narrow down where the problem is. Once you know which package caused the issue, show us how you added the package and what changes you made to theme-name/resources/assets/scripts/*

Hi there,

Thanks for that - I found the culprit.

This is this plugin: http://idangero.us/swiper/#.Wbfge9OGNE4

I installed it from my package.json

then, I basically import it at the top of my home.js using:
import Swiper from "swiper";

And then in my finalize() function:

new Swiper ('.swiper-container', {
          // Optional parameters
          //loop: true,
          slidesPerView: 3,
          paginationClickable: true,
          spaceBetween: 30,
          freeMode: true,
          //centeredSlides: true,
          autoplay: 2500,
          // Navigation arrows
          nextButton: '.swiper-button-next',
          prevButton: '.swiper-button-prev',
          breakpoints: {
              1024: {
                  slidesPerView: 4,
                  spaceBetween: 40,
              },
              768: {
                  slidesPerView: 3,
                  spaceBetween: 30,
              },
              640: {
                  slidesPerView: 2,
                  spaceBetween: 20,
              },
              320: {
                  slidesPerView: 1,
                  spaceBetween: 10,
              },
          },

      });