[英]Compiled against different NODE_MODULE_VERSION - Tree-sitter parser, ATOM package
我創建了一個 tree-sitter 解析器,它正在解析我們使用的一些遺留 SAP 語言,以便使包與 ATOM 兼容。 我將非常了解我所采取的行動,因為我對自己搞砸的地方不是很自信。
根據 tree-sitter 文檔,我閱讀了許多指南 - 我已經完成了以下操作:
將 D:\\path-to-project\\node_modules.bin 添加到 PATH
npm install -g node-gyp (I have installed the dependencies - MSVC 2017 and Python 2.7)
創建一個新目錄並 cd 到它:
npm init (followed the dialog)
npm install
npm install --save-dev nan
npm install --save-dev tree-sitter-cli
現在我們可以創建我們的 tree-sitter 語法.js 文件並生成 tree-sitter 解析器,所以我做了:
創建了grammar.js並記下了必要的語法打開CMD,cd到項目文件夾,然后:
tree-sitter generate
node-gyp configure
node-gyp build
tree-sitter test (To check if the parser is working correctly, which it does)
因此,現在我可以將解析器集成到 ATOM 包中。 因此,我通過 - 'npm publish' 將我創建的 tree-sitter 解析器發布到 npm,然后:
我從 ATOMs Generate package 函數創建了一個包,在包中創建了一個“grammar”目錄和一個具有以下值的 .cson 文件:
name: 'Human readable name'
scopeName: 'A unique, stable identifier for the language.'
type: 'tree-sitter' (indicates that we are using tree-sitter grammar not TextMate one)
parser: 'Here we must the npm package name that we published to NPM'
fileTypes: ['array of file extensions that the package will run on for example 'cpp'']
這就是有趣的地方。 在我的 ATOM 包目錄中的“npm install my-npm-package-name”之后,我在 ATOM 中收到一個錯誤:
The module '\\?\D:\Users\myUser\github\my-ATOM-package-name\node_modules\my-tree-sitter-npm-package
\build\Release\my-tree-sitter-npm-package_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 73. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
in D:\Users\myUser\.atom\packages\my-ATOM-package-name\grammars\the-cson-file-mentioned.cson
從我所做的網絡調查來看,這是因為 ATOM 使用了與我使用的不同的 NodeJs 版本(NodeJs v 12.4.0)。 這就是我陷入困境的地方,經過多次嘗試使用“電子重建”重新編譯后,我沒有成功就放棄了,並決定我需要更有經驗的幫手。
我正在 Windows 上開發和安裝。 NodeJS 與 nvm 一起安裝,我正在使用 v12.4.0 進行開發。
我設法解決了這個問題。 顯然或不明顯你應該:
npm install --save-dev electron@9.3.5 (the current electron version atom was at the time of the last edit of the answer)
npm install --save-dev electron-rebuild
electron-rebuild --version 9.3.5 (the current electron version atom was using at the time of the last edit of the answer)
如果它仍然抱怨您正在運行不同的版本,您應該:
node-gyp rebuild
electron-rebuild --version 9.3.5 (the current electron version atom was using at the time)
發布到 npm 之前:刪除 binding.gyp、package-lock.json 文件和 Electron 二進制文件夾
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.