Home > database >  How do I use require instead of import, while still being able to access properties of the variable?
How do I use require instead of import, while still being able to access properties of the variable?

Time:11-13

This works

import { keyboard } from "@nut-tree/nut-js"
keyboard.config.autoDelayMs = 0

This does not

var keyboard = require("@nut-tree/nut-js")
keyboard.config.autoDelayMs = 0

TypeError: Cannot set properties of undefined (setting 'autoDelayMs')

How do I do this?

CodePudding user response:

The first form takes the keyboard export (module.exports.keyboard), while the second form you posted takes the entire exports object and tries to set its .config.autoDelayMs property.

You probably want require("@nut-tree/nut-js").keyboard.

  • Related