我有一个用于React应用程序的服务器代码(从create react app创建):
$ awk -F: 'FNR==NR {a[$1]++; next} !a[$1]' file2 file1
apple:tasty
apple:red
kiwi:awesome
kiwi:expensive
grape:green
其他服务器端文件也使用“导入”。
尝试通过import config from './../config/config'
import app from './express'
import mongoose from 'mongoose'
// Connection URL
mongoose.Promise = global.Promise
mongoose.connect(config.mongoUri)
mongoose.connection.on('error', () => {
throw new Error(`unable to connect to database: ${mongoUri}`)
})
app.listen(config.port, (err) => {
if (err) {
console.log(err)
}
console.info('Server started on port %s.', config.port)
})
运行它时,出现以下错误:
node server.js
我应该如何启动我的react应用程序,以便客户端可以运行,也可以从一开始运行该server.js服务器?我通常在package.json中使用以下内容:
(function (exports, require, module, __filename, __dirname) { import config from
'./../config/config'
^^^^^^
SyntaxError: Unexpected token import
但是在这种情况下,node命令将不起作用。我尝试了一下但没有成功: Using Import In NodeJS server