【发布时间】:2017-02-28 10:42:35
【问题描述】:
我有一个项目在 dev 中运行良好,使用 babel-node 运行服务器。
但是尝试了 2 天后,我无法将其编译为 ES5。
我尝试运行 babel,但没有包含依赖项。 我尝试为服务器创建一个 webpack 配置,但我目前遇到了错误:
fs.js:634
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT: no such file or directory, open '/types/mime.types'
我用于服务器的 webpack 配置与我用于编译客户端代码的配置几乎相同 [100% 有效]:
var webpack = require('webpack');
var path = require('path');
var WebpackNotifierPlugin = require('webpack-notifier');
var BUILD_DIR = path.resolve(__dirname, 'static');
var APP_DIR = path.resolve(__dirname, 'src');
var DATA_DIR = path.resolve(__dirname, 'json');
module.exports = {
target: "node",
devtool: 'source-map',
// This will be our app's entry point (webpack will look for it in the 'src' directory due to the modulesDirectory setting below). Feel free to change as desired.
entry: [
APP_DIR + '/server.js',
],
// Output the bundled JS to dist/app.js
output: {
path: BUILD_DIR,
filename: 'prod-server.js',
},
node: {
fs: "empty",
net: "empty"
},
module: {
loaders: [
{ test: /\.jsx?$/, loaders: ['babel'], include: APP_DIR },
{ test: /\.json$/, loaders: ["json-loader"] }
]
},
plugins: [
// Set up the notifier plugin - you can remove this (or set alwaysNotify false) if desired
new WebpackNotifierPlugin({ alwaysNotify: true }),
]
};
如果 babel-node 可以顺利运行,那么必须有一种更简单的方法来将服务器编译为该节点可以运行的 ES5。
编辑:错误的完整堆栈跟踪:
fs.js:634
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT: no such file or directory, open '/types/mime.types'
at Error (native)
at Object.fs.openSync (fs.js:634:18)
at Object.fs.readFileSync (fs.js:502:33)
at a.load (/Users/funk/Development/Projects/jayeh_2015/static/prod-server.js:210:505)
at Object.<anonymous> (/Users/funk/Development/Projects/jayeh_2015/static/prod-server.js:210:934)
at Object.<anonymous> (/Users/funk/Development/Projects/jayeh_2015/static/prod-server.js:210:1129)
at t (/Users/funk/Development/Projects/jayeh_2015/static/prod-server.js:1:169)
at Object.e.exports (/Users/funk/Development/Projects/jayeh_2015/static/prod-server.js:29:2855)
at t (/Users/funk/Development/Projects/jayeh_2015/static/prod-server.js:1:169)
at Object.n (/Users/funk/Development/Projects/jayeh_2015/static/prod-server.js:1:7248)
【问题讨论】:
-
是否有更多关于该错误的堆栈跟踪?
-
你打赌。我将编辑问题并将其添加到底部。
-
根据stackoverflow.com/questions/31102035/…,我更改了我的 webpack 配置并得到了一个不同的错误,这可能是进步?它比第一个提供更多信息:“return binding.stat(pathModule._makeLong(path)); no such file or directory, stat '/favicon.ico'” 这让我觉得这个 'pathModule._makeLong' 没有路径很长......所以节点在错误的地方寻找这些文件。
-
哦,然后我看到“github.com/webpack/webpack/issues/1599”...无论如何我仍在寻找解决方案。编辑:服务器正在运行!!!!让我看看是否有任何东西加载...
-
好的,服务器工作正常,但没有加载,但我认为这是因为我一直在尝试让事情正常工作的路径。在我开始工作后,我会尝试将问题归结为解决方案......这并不简单......而且IMO对巴别塔人感到羞耻,因为他们没有提供简单的解决方案并强迫某人使用不同的工具只是为了获得编译源。编辑:无论它是否有效,都会有一百万条警告......
标签: node.js ecmascript-6 jsx babeljs