Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Uncaught TypeError: Object prototype may only be an Object or null: undefined

As I suspected, your original program has circular imports. Run.ts imports index.ts, which imports Customer.ts, which imports index.ts again. Since index.ts is already in the process of loading and itself depends on Customer.ts, the import { Entity } from "./index"; just binds the Entity of index.ts (which is not set yet) to the Entity of Customer.ts, and execution proceeds even though index.ts isn't finished loading. Then Entity is undefined at the time you try to extend it. You might argue that a circular import should be an error or that JavaScript engines should use some other algorithm that correctly handles your scenario; I'm not qualified to comment on why the current design was chosen. (Others feel free to add information about this.)

As you saw, changing Customer.ts to import from ./Entity directly instead of ./index breaks the cycle, and everything works as expected. Another solution would be to reverse the order of imports in index.ts.
Comment

Uncaught TypeError: Object prototype may only be an Object or null: undefined vite jws

// The cheapest way I found to “solve” this issue in vite is to mock node.js modules in vite.config.ts:

define: {
    global: {},
    stream: {},
    process: {},
 },

// and to fake “inherits” module and do the check there
{
resolve: {
    alias: {
      inherits: './inherits.js',
    },
  },
}

//in inherits.js you can put an easy check.
function inherits(ctor, superCtor) {
  if (!superCtor.prototype) return;
  // eslint-disable-next-line no-underscore-dangle
  ctor.super_ = superCtor;
  ctor.prototype = Object.create(superCtor.prototype, {
    constructor: {
      value: ctor,
      enumerable: false,
      writable: true,
      configurable: true,
    },
  });
}
module.exports = inherits;
Comment

PREVIOUS NEXT
Code Example
Javascript :: sequelize relation does not exist 
Javascript :: linear gradient css react js 
Javascript :: window.innerHeight react js 
Javascript :: js replace multiple 
Javascript :: how to remove whitespace only from first position of string js 
Javascript :: js password generator 
Javascript :: ngstyle background url angular 
Javascript :: angular bind style value 
Javascript :: queryselector get each element 
Javascript :: typescript class constructor overload 
Javascript :: json limit 
Javascript :: pushing element in array in javascript 
Javascript :: modulus of negative numbers 
Javascript :: jqueyr element is hide 
Javascript :: js host without port 
Javascript :: c# print object to json 
Javascript :: js browser tab inactive check 
Javascript :: ifsc code validation regex 
Javascript :: xmlhttprequest 
Javascript :: js get html content 
Javascript :: electron hide devtools 
Javascript :: change root color js 
Javascript :: javascript form post json data 
Javascript :: discord client.send_message js 
Javascript :: add new items in a select input using js 
Javascript :: suspense react 
Javascript :: dot env react native 
Javascript :: javascript inject html 
Javascript :: passing html vlaues to Javascript function 
Javascript :: jquery list all event listeners 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =