我正在尝试使用parceljs创建一个库,在npm运行后,我得到了
未定义未定义的ReferenceError:要求
package.json
{
"name": "social-tagger",
"version": "1.0.0",
"description": "",
"source": "src/index.ts",
"main": "dist/main.js",
"module": "dist/module.js",
"scripts": {
"watch": "parcel watch",
"build": "parcel build"
},
"author": "",
"license": "ISC",
"dependencies": {
"@yaireo/tagify": "^4.12.0",
"jquery": "^3.6.0"
},
"devDependencies": {
"@parcel/packager-ts": "^2.6.2",
"@parcel/transformer-typescript-types": "^2.6.2",
"@types/jquery": "^3.5.14",
"parcel": "^2.6.2",
"typescript": "^4.7.4"
}
}src/social.ts
import * as jQuery from 'jquery';如何正确导入jQuery
检查元素输出的


发布于 2022-07-02 12:52:51
向package.json添加目标
package.json
{
"name": "social-tagger",
"version": "1.0.0",
"description": "",
"source": "src/index.ts",
"main": "dist/main.js",
"module": "dist/module.js",
"scripts": {
"watch": "parcel watch",
"build": "parcel build"
},
"author": "",
"license": "ISC",
"dependencies": {
"@yaireo/tagify": "^4.12.0",
"jquery": "^3.6.0"
},
"devDependencies": {
"@parcel/packager-ts": "^2.6.2",
"@parcel/transformer-typescript-types": "^2.6.2",
"@types/jquery": "^3.5.14",
"parcel": "^2.6.2",
"typescript": "^4.7.4"
},
"targets":{
"main": {
"includeNodeModules": true
}
}
}创建一个名为jquery.ts的文件
jquery.ts
import jquery from "jquery";
export default ((window as any).jQuery = jquery);不要导入jquery,而是从jquery.ts导入
social.ts
import './jquery';https://stackoverflow.com/questions/72839146
复制相似问题