javascript - 当我在 WebStorm 中运行 JavaScript 文件时,说不能在模块外导入语句
问题描述
错误说这是 **import React, {Component} from 'react';
SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:891:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_enter code heremain_module.js:17:11**
解决方案
看起来好像您正在尝试使用 Node.js 运行您的 React 应用程序,通过右键单击您的组件.js
文件选择Run。这不应该起作用;您必须编译/构建您的应用程序,启动它托管的服务器,然后在浏览器中打开服务器 URL。对于使用 创建的应用程序create-react-app
,请按照以下说明进行操作https://www.jetbrains.com/help/webstorm/2020.1/react.html#react_running_and_debugging
推荐阅读
- php - 如何通过正则表达式覆盖这两种变体?
- angular - 如果 mime 类型是 angular2+ 中的 application/csv,如何打印 csv 文件?
- c# - grpc服务器类会被创建多次吗?
- django - 'Request' 对象没有'accepted_renderer',djangorestframework-datatables
- python - Python嵌套列表替换值
- node.js - 过滤节点 mongodb 中的对象数组
- reactjs - 无法使用序列化程序将 POST 请求从 React 前端发送到 Django Rest Framework?
- java - 并行流()和流()?
- java - Java Hadoop 生成没有结果
- javascript - 防止触发模糊事件的 Mousedown 事件处理程序