Nuxt.js: Error with Inversify.JS

Created on 16 Jul 2019  路  3Comments  路  Source: nuxt/nuxt.js

Version

v2.8.1

Reproduction link

https://codesandbox.io/s/nuxtnuxtjs-typescript-pub29

Steps to reproduce

// Uncomment this 2 lines:
// const Test = IocContainer.get("TestClass");
// console.log("Test", Test);

What is expected ?

Worked on the server and in the browser. To avoid errors with https://github.com/inversify/InversifyJS

What is actually happening?

Error is only on server.

Additional comments?

This error occurs only on the server, I do not understand why.
This code works:

if (process.browser) {
  const Test = IocContainer.get("TestClass");
  console.log("Test", Test);
}

This code does not work:

if (process.server) {
  const Test = IocContainer.get("TestClass");
  console.log("Test", Test);
}

I spent 6 hours on this problem and now it is important for me to solve it as soon as possible. Please give me some hint how to solve this problem.

I have used Inversify.JS many times with Nuxt, but it seems this error has appeared after the 2.4.0+ version, I checked it out.

Help me please. I am sure that the reason for the error in the Nuxt.js.

This bug report is available on Nuxt community (#c9498)
bug-report

Most helpful comment

It only affects dev mode. In production its false already. You can remove it and try to build rpoduction build and there wont be error too

All 3 comments

Add to your nuxt.config

  render: {
    bundleRenderer: {
      runInNewContext: false
    }
  }

@aldarund you are my savior! I spent 6 hours searching for a problem... Thank you very much! 馃槃馃帀

I found documentation about this.

This is not so important, but I just want to clarify: nothing bad will happen to my application if I change this setting? (it is planned to be large)

bundleRenderer option:

It is recommended to not use this option as Nuxt.js is already providing best SSR defaults and misconfiguration might lead to SSR problems.

Perhaps you see some other best workaround for the error?

Who is interested: runInNewContext: 'once' also gives my error.

It only affects dev mode. In production its false already. You can remove it and try to build rpoduction build and there wont be error too

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bimohxh picture bimohxh  路  3Comments

lazycrazy picture lazycrazy  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

uptownhr picture uptownhr  路  3Comments

danieloprado picture danieloprado  路  3Comments