【问题标题】:How to resolve migration error env: node\r: from Gatbsy-images to Gatsby-plugin-images with gatsby-codemods?如何解决迁移错误 env: node\r: from Gatbsy-images to Gatsby-plugin-images with gatsby-codemods?
【发布时间】:2021-11-30 03:20:33
【问题描述】:

我有大量代码希望通过 gatsby-codemods 从 gatsby-image 迁移到 gatsby-plugin-image。我关注了他们的文档here。所以问题是我在我的项目中使用了 yarn 并得到了一个 `env: node\r: No such file or directory。我尝试在 vi 中解决这个问题:(我认为这是因为 yarn 在所有系统上都使用 UNIX 行尾)

cd /myPathTo/gatsby-codemods
vi index.js
:set ff=unix 
:x

这是我尝试运行yarn gatsby-codemods gatsby-plugin-image时遇到的错误

Error: Command failed with exit code 127: /Users/mypath/node_modules/jscodeshift/bin/jscodeshift.js --ignore-pattern=**/node_modules/** --ignore-pattern=**/.cache/** --ignore-pattern=**/public/** --extensions=jsx,js,ts,tsx --transform /Users/mypath/gatsby-codemods/transforms/gatsby-plugin-image.js ./

at makeError (/Users/mypath/node_modules/execa/lib/error.js:60:11)
at Function.module.exports.sync (/Users/mypath/node_modules/execa/index.js:194:17)
at runTransform (/Users/mypath/node_modules/gatsby-codemods/bin/cli.js:35:33)
at Object.run (/Users/mypath/node_modules/gatsby-codemods/bin/cli.js:63:3)
at Object.<anonymous> (/Users/mypath/node_modules/gatsby-codemods/bin/gatsby-codemods.js:4:18)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) 

  exitCode: 127,
  signal: undefined,
  signalDescription: undefined,
  stdout: undefined,
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false

我该如何解决这个问题?

【问题讨论】:

    标签: node.js gatsby yarnpkg gatsby-image


    【解决方案1】:

    尝试通过 yarn 安装 jscodeshift 依赖项:

    npm install -g jscodeshift
    

    我认为您的问题是因为yarn doesn't convert Windows line endings

    另一种解决方法是直接调用node_modules 中的jscodeshift bin,绕过脚本顶部的shebang:

    node node_modules/.bin/jscodeshift -t
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-01
      • 2019-07-01
      • 2019-04-29
      相关资源
      最近更新 更多