我想将babelized server.js文件导出到lib
文件夹中。但是,当我构建Dockerfile
时,在RUN babel server.js -d lib
行中出现以下错误。我猜发生这种情况是因为找不到文件。我误会了吗?
错误消息
Step 11/14 : RUN babel server.js -d lib
---> Running in 68cef40456fb
/bin/sh: babel: not found
The command '/bin/sh -c babel server.js -d lib' returned a non-zero code: 127
Dockerfile
FROM node:10.16.3-alpine AS build
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ENV PATH="/app/node_modules/.bin:${PATH}"
COPY package.json ./
RUN npm install --silent --no-doc --no-ri
COPY server.js ./
RUN mkdir lib
RUN babel server.js -d lib
...
server.js
import App from './src/App';
import template from './src/template';
import { StaticRouter } from 'react-router-dom';
import express from 'express';
import path from 'path';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
const app = express();
app.use('/assets', express.static(path.join(__dirname, 'dist')));
app.get('/*', (req, res) => {
const context = {};
const renderingResult = ReactDOMServer.renderToString(
<StaticRouter location={req.url} context={context}>
<App/>
</StaticRouter>
);
let ssrPage = template('ssr test', '', renderingResult);
res.send(ssrPage);
});
app.listen(3000);
package.json
{
"name": "web.admin",
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/node": "^7.6.3",
"@babel/preset-env": "^7.6.3",
"@babel/preset-react": "^7.6.3",
...
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9",
"webpack-merge": "^4.2.2",
"webpack-node-externals": "^1.7.2"
},
"scripts": {
"start": "babel-node server.js",
"build": "webpack --config webpack.prod.js"
},
...
}