【发布时间】:2019-07-02 11:13:58
【问题描述】:
我正在开发 webpack 4.29.3 和 vue.js 2.6.3。我只是尝试使用 vue js 和 webpack 创建一个简单的 hello world 项目。我希望index.html 能够很好地呈现。但是我得到了错误: SyntaxError: invalid range in character class 这真的很奇怪,因为我没有对正则表达式做任何事情。这就是为什么我不确定要修复哪个部分。
vue-first.js:
import Vue from 'vue';
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
});
index.html:
<!doctype html>
<html>
<head>
<title>Getting Started</title>
</head>
<body>
<div id="app">
{{ message }}
</div>
<script src="todo.js"></script>
</body>
</html>
webpack.config.js
const path = require('path');
module.exports = {
entry: './src/js/vue-first.js',
output: {
filename: 'todo.js',
path: path.resolve(__dirname, 'dist')
}
};
package.json
{
"name": "vue-first",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^4.29.3",
"webpack-cli": "^3.2.3"
},
"dependencies": {
"vue": "^2.6.3"
}
}
完整的错误信息(来自 Safari):
[Error] SyntaxError: Invalid regular expression: range out of order in character class
RegExp (todo.js:7:3226)
(anonymous function) (todo.js:7:3226)
(anonymous function) (todo.js:7:63703)
n (todo.js:1:115)
(anonymous function) (todo.js:7:63775)
n (todo.js:1:115)
(anonymous function) (todo.js:1:904)
Global Code (todo.js:1:912)
更多详情,您可以查看我的Github。
【问题讨论】:
-
你是从 webpack 还是从浏览器收到错误的?它指的是哪个源代码行? (这个错误看起来像是一个正则表达式语法问题,但这里发布的代码中没有正则表达式。)
-
来自浏览器。
npm run build和npx webpack工作正常。它发生在todo.js的第 7 行。我已经列出了完整的错误消息。提前谢谢你。 -
todo.js中有什么内容? (您的 github 存储库中没有此类文件。)并为您的 JS 启用地图文件,以便浏览器可以为您提供预压缩/打包源代码参考。 -
它是 webpack 的输出。它是包含 Vue.js 和 vue-first.js 的缩小代码。这就是为什么我没有把它推到 Github 上。但为了您的方便,我现在推送了它。
标签: javascript vue.js webpack