简体   繁体   English

为什么 webpack 认为我的模块不是模块?

[英]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.

相关问题 为什么webpack在我的第一个条目以及页面包中都包含一个模块 - Why does webpack include a module in my first entry as well as my page bundle 如果宿主 React 应用程序不使用 Webpack,如何使用联合 React 模块? - How to use a federated React module if the host React application isn't using Webpack? Webpack为什么认为我正在运行开发版本? - Why does Webpack think I’m running a development build? 为什么 Typescript 认为我的枚举未定义? - Why does Typescript think my enum is undefined? 为什么我看到 webpack 模块 7 不是一个函数? - why i'm seeing webpack module 7 is not a function? 在Webpack的4个概念中,模块指的是什么? - What does module refer to in context of the 4 concepts of Webpack? Webpack找不到入口模块 - Webpack can't find Entry Module Webpack 5 Module Federation throwing error Module does not exist in the container - Webpack 5 Module Federation throwing error Module doesn't exists in the container 为什么我不能修改module.exports? 为什么我的浏览器在 `npm run build` 没有问题后会抱怨? - Why can't I modify module.exports? Why does my browser complain after no problems from `npm run build`? 为什么 React 不使用接口编译我的本地模块? - Why does React not compile my local module with an Interface?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM