Require is not defined nodejs

johnnE picture johnnE · Jul 13, 2016 · Viewed 39k times · Source

Trying to use this smartsheet api: http://smartsheet-platform.github.io/api-docs/?javascript#node.js-sample-code

and its telling me to do this for nodejs:

var client = require('smartsheet');
var smartsheet = client.createClient({accessToken:'ACCESSTOKEN'});

So i do this in my main.js file but I get the error: Uncaught ReferenceError: require is not defined

I think its because im new to nodejs/npm but I cannot find it anywhere where to actually put this require function. I think i need to mess with my node.js file but im note entirely sure. Any link to documentation or suggestions are greatly appreciated!

Answer

gyan deep picture gyan deep · Feb 14, 2020

Try Removing "type": "module", from package.json