Babel/Core JS找不到自己的文件--AWS EB Django

Babel/Core JS找不到自己的文件--AWS EB Django,django,npm,babeljs,amazon-elastic-beanstalk,Django,Npm,Babeljs,Amazon Elastic Beanstalk,我很难让ReactJS及其所有依赖项在AWS Elastic Beanstalk环境中正常工作。目前,我正在努力让巴贝尔工作。它似乎不知道自己安装到了哪里——它在哪个文件夹中。例如,您应该能够使用“@babel/preset env”作为预设名称,但我发现我需要提供完整路径,“/opt/elasticbeanstalk/eb_infra/node_modules/@babel/preset env”,否则它将无法找到它。(与其他预设/插件类似。) 我已经使用这种方法使大多数东西进入工作状态,除了

我很难让ReactJS及其所有依赖项在AWS Elastic Beanstalk环境中正常工作。目前,我正在努力让巴贝尔工作。它似乎不知道自己安装到了哪里——它在哪个文件夹中。例如,您应该能够使用
“@babel/preset env”
作为预设名称,但我发现我需要提供完整路径,
“/opt/elasticbeanstalk/eb_infra/node_modules/@babel/preset env”
,否则它将无法找到它。(与其他预设/插件类似。)

我已经使用这种方法使大多数东西进入工作状态,除了core js。它似乎在/tmp/中寻找自己的模块。奇怪,但我能从那里添加一个符号链接到它的实际位置。但是现在,它找不到
核心js/modules/es.string.split
。我查看了real modules文件夹,果然,该文件不存在

所以我的问题是,什么是文件
es.string.split
(除了显而易见的--string.split的一些polyfill),为什么它不寻找例如
es6.string.split
(它也不存在),为什么它丢失了,等等。我如何让它工作

我收到的错误消息:

[Application update [...]/Command 02_compress] : Activity execution failed, because: CommandError: An error occurred during rendering [...my_template].html: Error: Cannot find module 'core-js/modules/es.string.split' from '/tmp'
  at /usr/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:46:17
  at process (/usr/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:173:43)
  at ondir (/usr/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:188:17)
  at load (/usr/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
  at onex (/usr/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
  at /usr/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
  at FSReqWrap.oncomplete (fs.js:153:21)
安装.ebextensions文件:

# approach taken from https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/instance-configuration/install-nodejs.config

files:
  "/tmp/prep_node_installation.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #! /bin/bash
      curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -

  "/tmp/install_node.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #! /bin/bash
      yum -y install nodejs

  "/tmp/install_npm.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #! /bin/bash
      curl --silent --location http://npmjs.org/install.sh | sh

  "/tmp/install_babel.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #! /bin/bash
      npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/preset-react @babel/plugin-proposal-class-properties
      npm install --save core-js@3 @babel/polyfill
      npm install -g browserify

      # For some reason, core-js seems to be looking in /tmp/ for its files. So place a symbolic link from there to the actual folder that has the files.
      ln -sf /opt/elasticbeanstalk/eb_infra/node_modules/@babel/polyfill/node_modules/core-js /tmp/core-js


commands:
  05_prep_for_node_install:
    command: "sh /tmp/prep_node_installation.sh"
    ignoreErrors: false

  10_install_node:
    command: "sh /tmp/install_node.sh"
    ignoreErrors: false

  20_install_npm:
    command: "sh /tmp/install_npm.sh"
    ignoreErrors: false

  30_install_babel:
    command: "sh /tmp/install_babel.sh"
    ignoreErrors: false
Babel config.js文件:

const预设=[
[
//因为“@babel/preset env”不起作用。。。
“/opt/elasticbeanstalk/eb_infra/node_modules/@babel/preset env”,
{
目标:{
边缘:“17”,
火狐:“60”,
铬:“67”,
狩猎:“11.1”,
即:“11”,
},
useBuiltIns:“用法”,
corejs:3,
},
],
[
“/opt/elasticbeanstalk/eb_infra/node_modules/@babel/preset react”,
{}
],
];
常量插件=[
“/opt/elasticbeanstalk/eb_infra/node_modules/@babel/plugin提案类属性”,
];
module.exports={预设,插件};
我的应用程序已经设置为使用Django Compressor,因此这是从settings.py运行Babel以准备压缩的命令:

\u babel\u executable=os.environ.get(
“BABEL_可执行文件”,
#完整路径,因为它也找不到'babel'可执行文件
“/opt/elasticbeanstalk/eb_infra/node_modules/.bin/babel”
)
压缩\u预编译器=[
('text/javascript',
('cat{infle}|%s-f{infle}>{outfile}.tmp;'%_babel_可执行文件)+
'browserify{outfile}.tmp-o{outfile}',
('text/jsx',
('cat{infle}|%s-f{infle}>{outfile}.tmp;'%_babel_可执行文件)+
'browserify{outfile}.tmp-o{outfile}',
]

npm WARN saveError enoint:没有这样的文件或目录,打开“/opt/elasticbeanstalk/eb_infra/package.json”

从官方AWS线程[1]来看(这是我的问题),您可能正在压缩顶级目录,而不是压缩源代码本身

例如,您可能将所有文件都放在名为“Project”的文件夹中。您应该压缩并上传“项目”的内容,而不是压缩“项目”


[1]

这可能是因为Browerify的安装目录不匹配


执行$npm install-g browserify将全局搜索安装文件,而不是在AWS中设置的npm目录中。

您是否安装了预期的
core js
模块?整个相关安装包含在上述文件中。您可以看到
核心-js@3
安装是.ebextensions文件的一部分,大约在“/tmp/install_babel.sh”部分的一半。我怎样才能找到我需要的模块并安装它们呢?谢谢你的建议!但这是一个Python/Django环境,我正在其上安装Node.js,而不是Node.js本机环境。Django部分工作正常,直到我尝试安装Node/Babel/React,如果我放入package.json,它就会被忽略。这是失败的可能解释。包管理器很简单,但我确信它也适用于npm。我假设您的解决方案是不使用
-g
标志?(请在答案中加入您提出的解决方案)