react-sketch icon indicating copy to clipboard operation
react-sketch copied to clipboard

null & undefined in react build

Open jaswant100 opened this issue 3 years ago • 10 comments

Getting an error on react build console.log

utils.js:48 Uncaught TypeError: Cannot convert undefined or null to object at Function.getPrototypeOf () at Object. (utils.js:48) at c ((index):1) at Object. (URL.js:4) at c ((index):1) at Object. (webidl2js-wrapper.js:3) at c ((index):1) at Object. (index.js:3) at c ((index):1) at Object. (api.js:7)

jaswant100 avatar Dec 29 '20 06:12 jaswant100

Can you please provide more details or your utils.js ?

fosteman avatar Jan 01 '21 16:01 fosteman

Were you guys able to fix this? Even I have the same issue and it seems like this is originating from react-sketch itself. However its blowing up in utils.js of another package called whatwg-url.

rohitkrishna094 avatar Mar 03 '21 06:03 rohitkrishna094

I created a new typescript project and added just this piece of code

import React from 'react';
import { SketchField, Tools } from 'react-sketch';
import './App.css';

function App() {
  return (
    <div className="App" style={{ backgroundColor: 'black' }}>
      <SketchField width="100%" height="100%" widthCorrection={0} tool={Tools.Pencil} lineColor="#3182CE" lineWidth={3} />
    </div>
  );
}

export default App;

Of course it was complaining about no types being found, so I created another file called types.d.ts and added this into that file:

declare module 'react-sketch';

If I do npm start on the above code, it works perfectly fine. But if I do npm build(which is react-scripts build essentially), and then do serve -s build, it throws the same error in console:

Uncaught TypeError: Cannot convert undefined or null to object
    at Function.getPrototypeOf (<anonymous>)
    at Object.<anonymous> (utils.js:48)
    at a ((index):1)
    at Object.<anonymous> (URL.js:4)
    at a ((index):1)
    at Object.<anonymous> (webidl2js-wrapper.js:3)
    at a ((index):1)
    at Object.<anonymous> (index.js:3)
    at a ((index):1)
    at Object.<anonymous> (api.js:7)

Not sure how to proceed and fix this.

rohitkrishna094 avatar Mar 03 '21 06:03 rohitkrishna094

I have the exact same issue. In development mode everything is working, if I do npm build it throws the same error as mentioned by @rohitkrishna094.

The error goes away if I install and import react-sketch2 instead of react-sketch

buigabor avatar Mar 09 '21 10:03 buigabor

I have exactly the same error. Everything works fine locally, but the above error pops up after the build. I was inquiring where it came from, it points to the utils of the whatwg-url package.

Is it possible to fix this error? It makes the package completely useless

sptaszek92 avatar Jul 05 '21 08:07 sptaszek92

I am getting the same issue.

JaiPrakash-Saarthi avatar Nov 30 '21 17:11 JaiPrakash-Saarthi

Any updates? Is this related to "this is undefined" which I face in the built one not opening in the browser?! (while npm start works well...)

ADanayi avatar Jun 25 '22 08:06 ADanayi

I changed the package into react-sketch2 which has this issue fixed

sptaszek92 avatar Jun 27 '22 06:06 sptaszek92

@sptaszek92 Thanks. It works... However, my problem was something else that I'm going to post here:

For those who get the "this is undefined" error leading to this page:

When defining your classes, change the arrow functions function_name = (args) => {...function body...} into this.function_name = this.function_name.bind(this); in your constructors if you have inheritance.

I faced the mentioned error and spent 2-3 hours searching for the answer. The weird thing was there is no error in your npm start runs but when you npm build the product, the browser can't open the root index.html file (of course it's not related with your webserver including nginx, serve (npm) or ... but the build system.)

ADanayi avatar Jun 27 '22 08:06 ADanayi

I changed the package into react-sketch2 which has this issue fixed

Glad to hear it's solved! I think the reason your new package works now is somehow related to the solution I posted above. That fix might have been considered in react-sketch2.

ADanayi avatar Jun 27 '22 08:06 ADanayi