loopback-component-explorer production disabling cause error

Created on 27 Oct 2015  ยท  11Comments  ยท  Source: strongloop/loopback

Hello!
I just wanted to test production config of my application. I set NODE_ENV to "production" and called node server/server.js and it returned me this:

/vagrant/node_modules/loopback-boot/lib/config-loader.js:239
throw new Error('Cannot apply ' + fileName + ': ' + err);
^
Error: Cannot apply /vagrant/server/component-config.production.json: Cannot merge values of incompatible types for the option loopback-component-explorer.
at mergeComponentConfig (/vagrant/node_modules/loopback-boot/lib/config-loader.js:239:11)
at mergeConfigurations (/vagrant/node_modules/loopback-boot/lib/config-loader.js:138:5)
at loadNamed (/vagrant/node_modules/loopback-boot/lib/config-loader.js:76:16)
at Object.ConfigLoader.loadComponents (/vagrant/node_modules/loopback-boot/lib/config-loader.js:56:10)
at compile (/vagrant/node_modules/loopback-boot/lib/compiler.js:60:20)
at bootLoopBackApp (/vagrant/node_modules/loopback-boot/index.js:139:22)
at Object. (/vagrant/server/server.js:21:1)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)

here is my component-config.production.json

{
  "loopback-component-explorer": false
}

and middleware.production.json

{
  "final:after": {
    "loopback#errorHandler": {
      "params": {
        "includeStack": false
      }
    }
  }
}

Here is my slc -v

slc -v
strongloop v5.0.1 (node v4.2.1)
โ”œโ”€โ”€ [email protected] (d95b140)
โ”œโ”€โ”€ [email protected] (d008a3e)
โ”œโ”€โ”€ [email protected] (be6180a)
โ”œโ”€โ”€ [email protected] (62e539b)
โ”œโ”€โ”€ [email protected] (b96f806)
โ”œโ”€โ”€ [email protected] (f46e58f)
โ”œโ”€โ”€ [email protected] (1327018)
โ”œโ”€โ”ฌ [email protected] (46b06b4)
โ”‚ โ””โ”€โ”€ [email protected] (4ea7ee9)
โ”œโ”€โ”€ [email protected] (a374136)
โ”œโ”€โ”€ [email protected]
โ””โ”€โ”€ [email protected]

And i failed to understand why it crushes and why it shows stacktrace on it's crush

Could you help, please?

UPD: same problem with node v4.0.0

feature

Most helpful comment

same problem here, no need for a repo to reproduce the issue, just follow the documentation: https://docs.strongloop.com/display/public/LB/Environment-specific+configuration#Environment-specificconfiguration-DisablingAPIExplorer

All 11 comments

I suppose in your component-config.json, looks like :

{
  "loopback-component-explorer": {
    "mountPath": 'xxxx'
  }
}

The problem here is that when you set NODE_ENV to production, the merge utility of loopback will try to merge a boolean (in this case , false in your component-config.production.json) with Object and it fails to merge them.

The simplest way to disable explorer is to remove explorer.js and the component-config.{}.json file entirely in your production server. That is what I do.

Another workaround:

  • component-config.production.json as suggested:
{
  "loopback-component-explorer": false
}
  • rename component-config.json to component-config.development.json:
{
  "loopback-component-explorer": {
    "mountPath": "/explorer"
  }
}
  • create component-config.json with just:
{
}

Hey @echmykhun can you provide a sample repo for me to reproduce the issue, please? https://github.com/strongloop/loopback/wiki/Reporting-issues#bug-report

I'm having the same problem. While @pavlin99th's solution provides a temporary fix (thanks for that!), I think the right solution would be to completely replace the config object if the value in the production file is a boolean with the value false as in:

{
  "loopback-component-explorer": false
}

@mastertinner's idea is a good one!

@mastertinner agreed +1

+1

@echmykhun why is this being closed? How @mastertinner describes it, is how it should actually work in general when merging configurations.

@echmykhun so you don't think this is a problem that loopback need to solve?

same problem here, no need for a repo to reproduce the issue, just follow the documentation: https://docs.strongloop.com/display/public/LB/Environment-specific+configuration#Environment-specificconfiguration-DisablingAPIExplorer

@echmykhun Should re-open and accept PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bajtos picture bajtos  ยท  4Comments

bryannaegele picture bryannaegele  ยท  4Comments

JoeShi picture JoeShi  ยท  4Comments

daankets picture daankets  ยท  4Comments

ian-lewis-cs picture ian-lewis-cs  ยท  4Comments