Skip to content

ESM package.json in home directory crashes LSP #306

@Hacksore

Description

@Hacksore

I was looking into a Discord bug I found and funnily enough it also breaks the copilot LSP 😂.

[START][2024-08-03 11:32:06] LSP logging initiated
[ERROR][2024-08-03 11:32:06] .../vim/lsp/rpc.lua:770	"rpc"	"node"	"stderr"	"file:///Users/hacksore/.local/share/nvim/lazy/copilot.lua/copilot/index.js:3
global.__rootDirectory = __dirname + '/dist/';
                         ^

ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/hacksore/package.json' contains \"type\": \"module\". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/hacksore/.local/share/nvim/lazy/copilot.lua/copilot/index.js:3:26
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v20.12.2

Not sure this is fixable but raising the issue for awareness just in case others run into this.

tl;dr don't have a package.json in your homedir with "type": "module" 💀.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions