microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.43k stars 232 forks source link

Import Error #531

Closed childrentime closed 2 years ago

childrentime commented 2 years ago

Environment details

Issue description

when i use ts-node and typescript import pty from 'node-pty';

const term = pty.spawn(shell, ['--login'], {
    name: 'xterm-color',
    cols: 80,
    rows: 24,
    cwd: process.env.HOME,
});

it will throw error TypeError: Cannot read property 'spawn' of undefined';

and when i change to const pty = require('node-pty');

it works

childrentime commented 2 years ago

btw, window build tools seems to no need to install

Tyriar commented 2 years ago

@childrentime the build tools only need to be installed if you don't have the right tool chain installed.

You want import * as pty from 'node-pty', that's the equivalent to var pty = require('node-pty') on the readme.

childrentime commented 2 years ago

node.js latest version has window build tools built in. and what my point is, when i use import instead of require, it will throw runtime error

Tyriar commented 2 years ago

@childrentime a runtime error is expected though, if TS is configured correctly you should see an error as well:

image

childrentime commented 2 years ago

Oooooh. My mistake. Thanks❤️❤️❤️! I just used to default export😅.