我尝试将proj4js (2.5.0)作为一个ES6模块包含在webpack (4.27.1)项目中。
import proj4 from 'proj4';这导致了这个错误:
ERROR in ./node_modules/proj4/package.json
Module parse failed: Unexpected token m in JSON at position 0 while parsing near 'module.exports = __w...'
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token m in JSON at position 0 while parsing near 'module.exports = __w...'我能做些什么来绕过这个错误?
查看proj4js github页面上的问题报告时,由于proj4js显式地要求package.json,所以json加载程序看起来执行了两次:
proj4js/lib/version.js:
export {version as default} from '../package.json';发布于 2019-04-29 13:31:34
这个问题是由webpack-config中的这个加载程序引起的:
{
test: /\.(png|gif|jpg|jpeg|svg|xml|json)$/,
use: ["url-loader"]
}我将proj4排除在这个加载程序之外,它可以工作。
https://stackoverflow.com/questions/55868176
复制相似问题