所以,我在制作时遇到以下错误
localhost/:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
我很困惑,因为这只发生在生产中,并且在每个页面上,就像它要求HTML认为它是一个JS文件
我在生产中遇到过这个问题,当我访问像/ company / 55这样的路径时,我得到了同样的错误,我在webpack编译时使用了publicPath解决了这个问题,但这个错误对我来说是新的,而且它正在发生在所有页面上,该应用程序在生产中都没有。
我的webpack.config
const APP_ENTRY_PATH = paths.base(config.dir_client) + '/main.js'
webpackConfig.entry = {
app: __DEV__
? [APP_ENTRY_PATH, `webpack-hot-middleware/client?path=${config.compiler_public_path}__webpack_hmr`]
: [APP_ENTRY_PATH],
vendor: config.compiler_vendor
}
// ------------------------------------
// Bundle Output
// ------------------------------------
webpackConfig.output = {
filename: `[name].[${config.compiler_hash_type}].js`,
path: paths.base(config.dir_dist),
publicPath: config.compiler_public_path
}
// ------------------------------------
// Plugins
// ------------------------------------
webpackConfig.plugins = [
new webpack.DefinePlugin(config.globals),
new HtmlWebpackPlugin({
template: paths.client('index.html'),
hash: false,
favicon: paths.client('static/favicon.ico'),
filename: 'index.html',
inject: 'body',
minify: {
collapseWhitespace: true
}
})
]
if (__DEV__) {
debug('Enable plugins for live development (HMR, NoErrors).')
webpackConfig.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
)
} else if (__PROD__) {
debug('Enable plugins for production (OccurenceOrder, Dedupe & UglifyJS).')
webpackConfig.plugins.push(
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
unused: true,
dead_code: true,
warnings: false
}
})
)
}
编辑1:
在捕获的异常上暂停调试我发现了这个
function(e, t) {
var n = function() {
try {
Object({
toString: 0
} + "")
} catch (e) {
return function() {
return !1
}
}
return function(e) {
return "function" != typeof e.toString && "string" == typeof (e + "")
}
}();
e.exports = n
错误就是那个:
暂停异常:&#34;类型错误:无法将对象转换为原始值。&#34;
编辑2:
使用Caught Exceptions进行调试我有以下几个小时
在jquery-2.1.1.min.js:格式化
暂停异常:&#39; DOMException:无法执行&#39; querySelectorAll&#39; on&#39;元素&#39;:&#39; *,:x&#39;不是一个有效的slector。&#39;。
ib(function(a) {
var b = e.createElement("input");
b.setAttribute("type", "hidden"),
a.appendChild(b).setAttribute("name", "D"),
a.querySelectorAll("[name=d]").length && q.push("name" + M + "*[*^$|!~]?="),
a.querySelectorAll(":enabled").length || q.push(":enabled", ":disabled"),
a.querySelectorAll("*,:x"),
q.push(",.*:")
})),
(c.matchesSelector = $.test(s = o.matches || o.webkitMatchesSelector || o.mozMatchesSelector || o.oMatchesSelector || o.msMatchesSelector)) && ib(function(a) {
c.disconnectedMatch = s.call(a, "div"),
s.call(a, "[s!='']:x"),
r.push("!=", Q)
}),
然后它转到另一个代码的中断,换另一个选择器
暂停异常:&#39; DOMException:无法执行&#39; querySelectorAll&#39;在元素&#39;:&#39; [s!=&#39;&#39;]:x&#39;不是一个有效的slector。&#39;。
然后在vendor.js的另一个中断:格式化
暂停异常:&#39; TypeError:无法读取属性&#39; 1&#39; null&#39;。
代码:
function a() {
var t;
try {
t = window.localStorage[p]
} catch (e) {}
if (typeof t === s)
try {
var n = window.document.cookie
, r = n.indexOf(encodeURIComponent(p) + "=");
r && (t = /^([^;]+)/.exec(n.slice(r))[1])
} catch (e) {}
return void 0 === l.levels[t] && (t = void 0),
t
}
之后它突破了一些
throws new Error
行代码,在同一vendor.js:格式化
首先:
var B = !1;
try {
throw new Error
} catch (q) {
B = !!q.stack
}
然后开始:
function u() {
if (B)
try {
throw new Error
} catch (t) {
var e = t.stack.split("\n")
, n = e[0].indexOf("@") > 0 ? e[1] : e[2]
, r = a(n);
if (!r)
return;
return W = r[0],
r[1]
}
}
毕竟它转到app.js:格式化并在
中断暂停异常:&#34;类型错误:无法将对象转换为原始值。&#34;
function(e, t) {
var n = function() {
try {
Object({
toString: 0
} + "")
} catch (e) {
return function() {
return !1
}
}
return function(e) {
return "function" != typeof e.toString && "string" == typeof (e + "")
}
}();
e.exports = n
我还是输了