标签: babel-cli

如何在pm2中使用babel-node

我想用pm2软件包管理我的节点进程。如果我的代码中没有任何es6语法,那么我不需要添加babel-node,并且没有任何es6语法代码就可以在此代码行中将我的代码与pm2一起运行

pm2 start server.js
Run Code Online (Sandbox Code Playgroud)

但是,一旦我像这样添加es6语法的任何代码行

import express from 'express';
Run Code Online (Sandbox Code Playgroud)

我收到意外的令牌导入错误。

如您所知,要解决此问题,我们必须添加babel-node程序包。

但是当我使用这行命令来编译我的代码时

pm2 start server.js --interpreter babel-node
Run Code Online (Sandbox Code Playgroud)

我得到这个错误

Error: spawn babel-node ENOENT
at _errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
Run Code Online (Sandbox Code Playgroud)

奇怪的是,如果我不使用pm2并使用此行代码运行代码

babel-node server.js
Run Code Online (Sandbox Code Playgroud)

一切都好。

node.js pm2 babel-node babel-cli

6
推荐指数
2
解决办法
6633
查看次数

What is the difference between babel-cli and @babel/cli?

What is the difference between @babel/node and babel-node?
I did yarn add babel-node --dev but I had error. So I did yarn add @babel/node --dev, it worked. What is the meaning of @?

node.js babel-cli

6
推荐指数
1
解决办法
217
查看次数

npx babel 不从 babel.config.js 读取配置

npx babel index.js从命令行运行时,我希望能看到从 babel.config.js 应用我的 babel 配置

但事实似乎并非如此,因为我想知道为什么会这样?

// babel.config.js
module.exports = function babel(api) {
 api.cache(true);
   return {
     presets: ['module:metro-react-native-babel-preset'],
     plugins: [
       [
         'babel-plugin-root-import',
         {
           rootPathSuffix: './src',
           rootPathPrefix: '~/',
         },
       ],
     ],
   };
 };

// index.js
import { AppRegistry } from 'react-native';
import App from '~/App';
AppRegistry.registerComponent("App Name", () => App)

// Expected output from npx babel index.js
import { AppRegistry } from 'react-native';
import App from './src/App'; // Note the change from '~' to './src' using babel-plugin-root-import
AppRegistry.registerComponent("App …
Run Code Online (Sandbox Code Playgroud)

javascript babeljs react-native babel-cli npx

6
推荐指数
1
解决办法
5586
查看次数

使用 babel-node 时如何将选项传递给节点

Babel CLI 文档(https://babeljs.io/docs/usage/cli/):

babel-node [options] [ -e script | script.js ] [arguments]
Run Code Online (Sandbox Code Playgroud)

但是当尝试为 Node 增加分配的内存时:

babel-node --max-old-space-size=16384 script.js
Run Code Online (Sandbox Code Playgroud)

参数--max-old-space-size=16384似乎被忽略

某人是否知道这是否应该有效,如果不应该 - 一些解决方法?

node.js babeljs babel-cli

5
推荐指数
2
解决办法
5227
查看次数

有什么方法可以覆盖本地babelrc配置?

我有一个.babelrc文件,其中某些配置要在某些情况下(与环境无关)覆盖。不幸的是,babel文档对于所传递的配置的优先顺序不是很清楚(例如,.babelrc,babel-loader,babel.transform,babel-cli等)。

另外,使用babel-cli时是否可以将查询参数或选项传递给es2015等babel预设?

babel babel-cli babel-core

5
推荐指数
0
解决办法
304
查看次数

使用babel-cli时如何将选项传递给插件

是否可以在babel-cli --plugins参数中声明插件选项?我在文档中找不到任何提及或示例。

具体来说,我正在尝试翻译从.bashrc文件如下(如描述这里)成通天-CLI --plugins参数:

...
"plugins": [
[
   "babel-plugin-transform-require-ignore",
   {
      "extensions": [".css", ".sass", ".scss"]
   }
]]
...
Run Code Online (Sandbox Code Playgroud)

非常感谢您的协助。

babel babel-cli

5
推荐指数
0
解决办法
97
查看次数

Babel 输出路径来维护输入路径的目录结构

给定以下示例目录结构:

srcDir/file1.js
srcDir/subDir1/file2.js
srcDir/subDir2/file3.js
Run Code Online (Sandbox Code Playgroud)

我想处理这些文件,babel-cli以便输出文件destDir以相同的相对目录结构结束。

那是:

destDir/file1.js
destDir/subDir1/file2.js
destDir/subDir2/file3.js
Run Code Online (Sandbox Code Playgroud)

我不想处理所有文件srcDir,只处理其中的一些。

我想我必须指定一个输入目录、一个文件路径列表和一个输出目录。
但是 Babel 的命令行帮助并没有解释怎么做。

Usage: babel [options] <files ...>

Options:
  -f, --filename [filename]                   filename to use when reading from stdin - this will be used in source-maps, errors etc
  --presets [list]                            comma-separated list of preset names
  --plugins [list]                            comma-separated list of plugin names
  --config-file [path]                        Path to a .babelrc file to use
  --env-name [name]                           The name of the 'env' to use when loading configs …
Run Code Online (Sandbox Code Playgroud)

output-directory babeljs babel-cli

5
推荐指数
1
解决办法
2991
查看次数

`npm install @babel/cli` 对四个模块显示“WARN deprecated”。我该如何解决这些弃用问题?

我的设置

  • MacOS = Catalina 10.15.4(最新版本)
  • nvm = 0.35.3(最新版本)
  • node.js = 12.16.3(最新 LTS 版本)。安装在 nvm 目录内。
  • npm = 6.14.4(最新版本)。安装在 nvm 目录内。

注意:. 内部没有全局安装usr/local

我的问题

我用来npm init -y创建我的 package.json。这里没有问题。

我用npm install --save-dev @babel/core。这里没有问题。我得到的版本是 7.9.6。

然后当我使用时npm install --save-dev @babel/cli我会回来:

npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.

npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. …

npm babel-cli

4
推荐指数
1
解决办法
3659
查看次数

无法为具有babel-node的节点启动VSCode调试器

当我输入npm run debug控制台时,我得到:"Debugger listening on ws://127.0.0.1:3090/d17dfe56-4fa4-4686-a62e-d07cff78c834".当我在chrome中找到这个地址时,我唯一看到的就是"WebSockets request was expected".我应该调整配置的哪些部分以使调试器工作?我正在使用最新版本的nodejs.

package.json脚本

"scripts": {
    "prod": "webpack -p --env.production --progress",
    "start": "babel-node --presets es2015 server/server.js",
    "watch": "nodemon --exec npm run start",
    "debug": "babel-node --presets es2015 server/server.js --inspect --debug-brk=3090"
  }
Run Code Online (Sandbox Code Playgroud)

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch via NPM",
            "type": "node",
            "request": "launch",
            "runtimeExecutable": "npm",
            "program": "${workspaceRoot}/server/server.js",
            "restart": true,
            "runtimeArgs": [
                "run-script", "debug"
            ],
            "port": 3090
        },
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome against …
Run Code Online (Sandbox Code Playgroud)

node.js package.json visual-studio-code babel-node babel-cli

3
推荐指数
1
解决办法
1458
查看次数

我如何告诉 Babel CLI 忽略任何带有“__”的路径?

"@babel/cli": "^7.2.3",
Run Code Online (Sandbox Code Playgroud)

看起来真的很简单。

https://babeljs.io/docs/en/babel-cli#ignore-files

 babel src --out-dir lib --ignore "src/**/*.spec.js","src/**/*.test.js"
Run Code Online (Sandbox Code Playgroud)

所以我这样设置:

babel src --out-dir cjs --ignore "**/_*" --copy-file --watch
Run Code Online (Sandbox Code Playgroud)

全局参考: https: //github.com/isaacs/node-glob

但我在输出中看到了这一点:

add:cjs/__mocks__/@xyz/common-fn.js
add:cjs/middleware/__mocks__/uuid.js 
Run Code Online (Sandbox Code Playgroud)

好的,我试试这个:

babel src --out-dir cjs --ignore "**/_+","_+" --copy-file --watch
Run Code Online (Sandbox Code Playgroud)

还有这些:

babel src --out-dir cjs --ignore "**/_*/*.*\ --copy-file --watch 
babel src --out-dir cjs --ignore "**/__mocks__/*.*",  --copy-file --watch 
babel src --out-dir cjs --ignore "[src|middleware]/**/__mocks__/*.*" --copy-file --watch"
babel src --out-dir cjs --ignore "**/_+/**/*.*" --copy-file --watch
Run Code Online (Sandbox Code Playgroud)

每次结果都一样。看起来最后一个应该有效:忽略任何具有零个或多个目录的路径,后跟一个名称中至少有一个 _ 的目录,然后是零个或多个目录,然后是与任何模式匹配的文件。我读得对吗?

然后我尝试非常具体:

babel src --out-dir cjs --ignore "nes/middleware/__mocks__/*.js", --copy-file …
Run Code Online (Sandbox Code Playgroud)

glob node.js babeljs babel-cli

3
推荐指数
1
解决办法
4371
查看次数

使用 Babel-cli 手动编译 React JSX

如何.jsx使用npx babel-cli [inpfile].jsx --out-file [outfile].js --plugin=@[someplugin]命令编译文件。我已经尝试过--plugin=@plugin-transform-react-jsx,但它在第一个 JSX 表达式上给出了错误。

我安装了 babel-cli、babel-core 等软件包。

我可以使用create-react-app并且一切正常,但我想手动执行此操作,编译 JSX。

另外,如果可以使用相同的过程将 ES6 转换为 ES5 ;请同时说明。

任何帮助,将不胜感激。

jsx reactjs babeljs babel-cli babel-core

2
推荐指数
1
解决办法
1090
查看次数

使用 npx babel-node 时出现“意外标记 {”

这是我的脚本test.js

import 'jsdom-global/register';
import 'canvas';
console.log('done');
Run Code Online (Sandbox Code Playgroud)

这是我的 package.json:

{
  "name": "test-jsdom",
  "description": "Test",
  "version": "0.1.0",
  "author": "anthony@me.com",
  "dependencies": {
    "canvas": "^1.6.7"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-0": "^6.24.1",
    "jsdom": "^11.3.0",
    "jsdom-global": "^3.0.2"
  }
}
Run Code Online (Sandbox Code Playgroud)

当我运行时npx babel-node test.js,我遇到了这个错误

/Users/antkong/test/node_modules/jsdom/lib/api.js:10
const { URL } = require("whatwg-url");
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Module._extensions..js (module.js:416:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/antkong/test/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at …
Run Code Online (Sandbox Code Playgroud)

node.js babeljs babel-cli

1
推荐指数
1
解决办法
7087
查看次数