[英]ParseError: 'import' and 'export' may appear only with 'sourceType: module', browserify
I am using django-compressor and I want to es5/es6 features on my project.我正在使用django-compressor ,我想在我的项目中使用es5/es6功能。 I am setting the pre-compiler option as follow:
我将预编译器选项设置如下:
NODE_MODULES = BASE_DIR / 'node_modules'
COMPRESS_PRECOMPILERS = (
('text/javascript',
'browserify {{infile}} -t {node_modules}/babelify -o {{outfile}} --presets {node_modules}/@babel/preset-env'.format(node_modules=NODE_MODULES)),
('module',
'browserify {{infile}} -t {node_modules}/babelify -o {{outfile}} --presets {node_modules}/@babel/preset-env'.format(node_modules=NODE_MODULES)),
)
As you noticed browserify is installed globally and babelify and @babel/preset-env are installed locally inside the project.正如您所注意到的, browserify是全局安装的,而babelify和@babel/preset-env是在项目中本地安装的。
From the docs @babel/preset-env
now are the recommended presets to use, but I am getting the following error:从文档中
@babel/preset-env
现在是推荐使用的预设,但我收到以下错误:
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
According to my understanding, when using babel/preset-env , you do not need any other preceding presets eg babel-preset-es2015 and others, correct?据我了解,当使用babel/preset-env时,您不需要任何其他前面的预设,例如babel-preset-es2015等,对吗? if yes what are the possible reasons for this issue?
如果是,这个问题的可能原因是什么?
Although the command was working fine, it seems there was an syntax errors on how I specify the presets, anyway I have fixed like that:尽管该命令运行良好,但在我如何指定预设方面似乎存在语法错误,无论如何我已经修复了这样的问题:
COMPRESS_PRECOMPILERS = (
('text/javascript',
'browserify {{infile}} -o {{outfile}} -t [ {node_modules}/babelify --presets [ {node_modules}/@babel/preset-env ] ]'.format(node_modules=NODE_MODULES_LOCAL)),
('module',
'browserify {{infile}} -o {{outfile}} -t [ {node_modules}/babelify --presets [ {node_modules}/@babel/preset-env ] ]'.format(node_modules=NODE_MODULES_LOCAL)),
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.