我正在尝试导入使用 npm 下载的模块。
我的 json 文件是:
{
"name": "nodejs-web-app1",
"version": "0.0.0",
"description": "NodejsWebApp1",
"main": "server.js",
"author": {
"name": ""
},
"dependencies": {
"fs": "^0.0.1-security",
"http": "^0.0.1-security",
"node-pandas": "^1.0.5",
"node-static": "^0.7.11",
"require": "^2.4.20",
},
}
我有我的 html 文件:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Home</title>
<script type="module" src="functions.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<h1>Dashboard</h1>
<p>Welcome!</p>
<button onclick="scraper()">CLICK</button>
<label id="label">Reponse</label>
</body>
</html>
我的functions.js 文件
import pd from 'node-pandas';
function scraper() {
const s = pd.Series([1, 9, 2, 6, 7, -8, 4, -3, 0, 5])
console.log(s);
document.getElementById('label').innerHTML = 'A computer science portal for geeks';
}
和我的 server.js 文件:
var nStatic = require('node-static');
var http = require('http');
var fs = require('fs');
var port = process.env.PORT || 8080;
var file = new nStatic.Server(__dirname);
http.createServer(function (req, res) {
file.serve(req, res);
}).listen(port);
但是运行代码时出现错误
未捕获的类型错误:无法解析模块说明符“node-pandas”。
相对引用必须以“/”、“./”或“../”开头。
我尝试过,但它也给出了另一个错误。
如果我写:
import pd from './node-pandas';
or
import pd from '../node-pandas';
I get:
获取http://localhost:1337/node-pandas net::ERR_ABORTED 404(未找到)
我的项目有这样的结构:
- myproject
- 服务器.js
- 函数.js
- 索引.html
- 包.json
- node_modules
我正在使用 Visual Studio 2019
知道我做错了什么吗?