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!
To fix this, remove "type": "module" from your package. json and make sure you don't have any files ending with . mjs . This can happen with anything in your project folder.
You can think of the require module as the command and the module module as the organizer of all required modules. Requiring a module in Node isn't that complicated of a concept. const config = require('/path/to/file'); The main object exported by the require module is a function (as used in the above example).
This usually happens because your JavaScript environment doesn't understand how to handle the call to require() function you defined in your code. Here are some known causes for this error: Using require() in a browser without RequireJS.
Your ReferenceError: require is not defined likely has one of two causes: You tried using require in a browser environment. You are in a Node. js environment but your project has "type": "module" in its package.
Try Removing "type": "module", from package.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With