我正在构建一个简单的应用,该应用使用Nact库演示演员模型。
我现在要处理的错误是:
未捕获的TypeError:无法解析模块说明符“ nact”。相对引用必须以“ /”、“./”或“ ../”开头
这是package.json:
{
"name": "actor-model-with-nact-demo-020120",
"version": "1.0.0",
"description": "Adam's Actor Model with Nact Demo",
"main": "server.js",
"dependencies": {
"express": "^4.17.1",
"nact": "^7.2.2",
"nodemon": "^2.0.2"
},
"devDependencies": {},
"scripts": {
"dev": "nodemon ./server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Adam Dudley",
"license": "MIT"
}
这是server.js:
const express = require('express')
const path = require('path')
const app = express()
const port = process.env.PORT || '8000'
app.use(express.static(__dirname + '/public'))
app.use('/static', express.static('./static/'))
app.get('/static', function(req, res) {
res.sendFile(path.join(__dirname + '/static/app.js'))
})
app.get('/', function(req, res) {
res.sendFile(__dirname + '/public/views/index.html')
})
app.listen(port, () => {
console.log(`Listening to requests on http://localhost:${port}`)
})
这是index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Adam's Actor Model with Nact Demo</title>
</head>
<body>
<h1>Adam's Actor Model with Nact Demo</h1>
<script src="static/app.js" type="module"></script>
</body>
</html>
这是app.js:
import { start, dispatch, stop, spawnStateless } from 'nact'
const system = start()
const greeter = spawnStateless(
system,
(msg, ctx) => console.log(`Hello ${msg.name}`),
'greeter'
)
dispatch(greeter, { name: 'World!' })
答案 0 :(得分:0)
作者在这里。我不太清楚这里的确切问题,但是就目前而言,Nact仅在服务器端得到正式支持。您可能 使其能够在浏览器中运行,但是您可能必须填充setImmediate
才能这样做。
由于Nact是commonjs模块,因此您需要使用诸如Parcel或Webpack之类的捆绑程序,才能将库转换为适当的模块格式。