[英]Why does webpack think my module isn't a module?
I'm trying to import react in the typical way:我试图以典型的方式导入反应:
import React from 'react'
but I'm getting this error:但我收到此错误:
Uncaught SyntaxError: Cannot use import statement outside a module
What could cause webpack to not treat my file properly as a module?什么可能导致 webpack 无法正确地将我的文件视为模块?
One likely cause is that the HTML is trying to point to the raw, uncompiled source script, rather than the script which is run through babel and compiled by webpack.一个可能的原因是 HTML 试图指向原始的、未编译的源脚本,而不是通过 babel 运行并由 webpack 编译的脚本。
The location of the uncompiled source script is whatever the path to that file is in the repository.未编译的源脚本的位置是该文件在存储库中的路径。
The location of the compiled output script is whatever the webpack.config.js
output filename is set to, with the path being the dev server path or if a production build, whatever the output path is set to. The location of the compiled output script is whatever the
webpack.config.js
output filename is set to, with the path being the dev server path or if a production build, whatever the output path is set to.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.