当我试图运行时:“包裹手表./public/js/index.js -ot-out-dir ./public/js-out-file bundle.js”我遇到了这个错误。我已经尝试了这个问题的答案,但它没有起作用。 Index.js:
import '@babel/polyfill';
import { displayMap } from './mapbox';
import { login } from './login';
// DOM ELEMENTS
const mapbox = document.getElementById('map');
const loginForm = document.querySelector('.form');
// DELEGATION
if (mapbox) {
const locations = JSON.parse(mapbox.dataset.locations);
displayMap(locations);
}
if (loginForm) {
document.querySelector('.form').addEventListener('submit', (e) => {
e.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
login(email, password);
});
}
login.js:
import axios from 'axios';
export const login = async (email, password) => {
console.log(email, password);
try {
const res = await axios({
method: 'POST',
url: 'http://127.0.0.1:3000/api/v1/users/login',
data: {
email,
password,
},
});
if (res.data.status === 'success') {
alert('Logged in successfully!');
window.setTimeout(() => {
location.assign('/');
}, 1500);
}
console.log(res);
} catch (err) {
alert(err.response.data.message);
}
};
您没有提供唯一重要的文件,package.json,但我相信我可以解决这个问题。删除节点模块不会产生任何效果。 如果有的话,您必须删除.parcel-cache.
您必须使用基本上是版本1的包裹捆绑器;它几乎与包裹V1相同,但用于插件。 现在已弃用。 包裹V1插件与包裹V2不兼容,因为插件系统已完全更改,因此CLI也是如此。don: NPM安装包裹捆绑器-Save-dev
"scripts": {
"start": "nodemon server.js",
"watch:js": "parcel watch ./public/js/index.js --dist-dir ./public/js/bundle",
},
{
"devDependencies": {
"parcel": "^2.13.3",
"prettier": "^3.4.2"
},
"targets": {
"main": false,
"default": {
"distDir": "./public/js/bundle"
}
},
}