google / zx

A tool for writing better scripts

Home Page:https://npmjs.com/package/zx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Autocomplete in VS Code - ERR_MODULE_NOT_FOUND

mak1A4 opened this issue · comments

Expected Behavior

Autocomplete for globals in vscode show up

Actual Behavior

I get an "ERR_MODULE_NOT_FOUND" error when executing a script which cointains import zx/globals

Steps to Reproduce the Problem

  1. Install zx globally either from npm or directly from github repo
  2. Execute the following script
#!/usr/bin/env zx
import 'zx/globals'
console.log(1 + 5)

For me this results in the following error:

node:internal/errors:465
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'zx' imported from /Users/myUser/Scripts/calc.mjs
    at new NodeError (node:internal/errors:372:5)
    at packageResolve (node:internal/modules/esm/resolve:908:9)
    at moduleResolve (node:internal/modules/esm/resolve:957:20)
    at defaultResolve (node:internal/modules/esm/resolve:1173:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:604:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

I'm not sure if this is a bug or I'm doing something wrong or missing something obvious.

Specifications

  • Platform: MacOS Apple Silicon (M1 Pro) - Node.js v17.9.0

Remove line: import 'zx/globals'

this is esm limitation.

So there currently is no way to get autocompletion in vscode if zx is installed globally and not locally?
If so, maybe update the Readme because there it's stated that this is how you should get autocompletion.

It’s possible use reference.

Thanks this // <reference 'zx/globals' /> worked : )

Thanks this // <reference 'zx/globals' /> worked : )

Hi, how did u use reference directive 😂? @mak1A4

I use like below but it said "Cannot find type definition file for 'zx/globals'.". Did u also install zx as a global module?

/// <reference types="zx/globals" />

I have the issue too. The readme should be fixed to say that its not possible. I also added // <reference 'zx/globals' /> but nothing happened.

@bluebrown
I installed zx in node module path($HOME in my case), then import { $ } from 'zx', and then the ts intellisense is working. You could have a try~

ezoic increase your site revenue