javascript - submit data to node.js server without form. no require no import , they don't work
问题描述
I know that maybe I get some negative votes. but it is not a big problem.I have no other option. I tried too much to send data to my node.js server without using form. I used axios. but my main.js doesn't know axios. i installed it
npm install axios
I imported it
import axios from ('axios')
but I got the error ( unexpected Identifier)
after that I tried require
var axios = require ('axios')
but I got the error ( require is not defined)
I installed browserify
npm install broweserify
after that I bundled it with this code
browserify main.js -o bundle.js
but the same error still remains
require is not defined.
has somebody a solution.
APPRECIATED
解决方案
您的导入语法似乎是错误的,也许这就是原因。导入时不需要括号:
import axios from 'axios'
我还猜测您是在前端而不是在 node.js 中运行此代码。这可能就是您收到“未定义要求”错误的原因。(见:https ://stackoverflow.com/a/9901097/7228779 )
看起来您broweserify
在安装命令中拼错了 browserify (not ),所以这也可能是一个问题。
推荐阅读
- php - 在 Yii2 ActiveForm 中上传不同属性的文件
- rabbitmq - 更新证书后,RabbitMQ Shovel over TLS 错误与 badmatch
- applescript - 如何从键盘快捷键返回值
- python - 在 Python3 上进行 301 重定向后 Pycurl 无法上传
- websocket - 读取 WebSocket 客户端数据到服务器 vb.net
- javascript - 为什么这种排序代码会导致 Chrome 和 Firefox 之间的值不同?
- java - Firebase 用户退出
- youtube-api - OAuth授权用户不是按关键字搜索视频吗?
- sql - 如何获取不在内部连接sql中的列,使用union all是很多时间
- python - Python如何重用一个Mock以避免多次编写mock.patch?