【发布时间】:2021-02-19 18:04:05
【问题描述】:
我正在尝试导入我用 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';
或
import pd from '../node-pandas';
我明白了:
GET http://localhost:1337/node-pandas net::ERR_ABORTED 404(未找到)
我的项目有这样的结构:
- 我的项目
- server.js
- functions.js
- index.html
- package.json
- node_modules
- 节点熊猫
我正在使用 Visual Studio 2019
知道我做错了什么吗?
【问题讨论】:
标签: javascript