小编X H*_*xha的帖子

无法将 JSX 与 nodejs ESM 模块加载器一起使用

我试图运行一个简单的代码块,以 React "render" method 为特色,但浏览器没有显示文本。

import React from 'react';
import ReactDOM from 'react-dom';

ReactDOM.render(<h1>Hello World</h1>,document.getElementById('root'));
Run Code Online (Sandbox Code Playgroud)

我使用 VS Code 作为编辑器,因此我输入了“运行和调试 Node.js”命令。它提出了以下警告

(node:3004) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
Run Code Online (Sandbox Code Playgroud)

在 package.json 文件中设置“type:module”解决了问题,但另一方面出现了另一个问题

(node:18968) ExperimentalWarning: The ESM module loader is experimental.    
warning.js:32
SyntaxError: Unexpected token '<'
 at Loader.moduleStrategy (internal/modules/esm/translators.js:81:18)
 at async link (internal/modules/esm/module_job.js:37:21)
Run Code Online (Sandbox Code Playgroud)

那不允许我写任何标签。我错过了什么,我该如何解决?下面是 index.html 文件和文件结构

<html>
    <head>
        <title> React Test</title>
    </head>

    <body>
        <div id="root"></div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

文件结构

node.js node-modules reactjs

6
推荐指数
1
解决办法
1128
查看次数

在python中接收用户输入时类型不匹配

我运行以下程序作为教学练习:

height = input("State your height : ")
age = input("State your age : ")

if type(height) == float and type(age) == int:
    print(f"You're {height} m tall and {age} years old")
else:
    print("\n You've made a mistake ! Enter your data again .")
    height = input("State your height : ")
    age = input("State your age : ")
    print(f"You're {height} m tall and {age} years old")
Run Code Online (Sandbox Code Playgroud)

具有以下输入和输出:

State your height : 2.2
State your age : 10

 You've made a mistake …
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
70
查看次数

标签 统计

node-modules ×1

node.js ×1

python ×1

reactjs ×1