Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

When importing GSAP into my TypeScript project, the browser says it cannot find GSAP

I am working on a TypeScript project using THREE.js and GSAP. This is my first TypeScript so maybe it's something obviously I am missing but whenever I import GSAP into my project I get an error in the browser.

The app is using express as the server and compiling the TypeScript code with

"dev": "concurrently -k "tsc -p ./src/server -w" "tsc -p ./src/client -w" "nodemon ./dist/server/server.js""

So every time I make a change it compiles the TypeScript in the /dist folder which is where my index.html file is.

I have tried a number of different GSAP plugins and import styles but I get the same issue every time. Here is an example of me importing gsap into my file.

import { gsap } from "gsap";
import { DrawSVGPlugin } from "gsap/DrawSVGPlugin";
gsap.registerPlugin(DrawSVGPlugin);

Then when I go to the browser I get an error in the console saying this. enter image description here

I don't know if I need to add anything to my tsconfig.json file maybe? I have a couple of configurations for some relative paths for THREE.js so maybe I need something similar for GSAP?

Here is my tsconfig.json file

{
"compilerOptions": {
    "target": "ES6",
    "module": "ES6",
    "outDir": "../../dist/client",
    "baseUrl": ".",
    "paths": {
        "/build/three.module.js": ["../../node_modules/three/src/Three"],
        "/jsm/*": ["../../node_modules/three/examples/jsm/*"]
    },
    "moduleResolution": "node"
},
"include": [
    "**/*.ts"
]
}

The in the express server I am adding those static files like so

app.use('/jsm/libs/dat.gui.module', express.static(path.join(__dirname, '../../node_modules/three/examples/jsm/libs/dat.gui.module.js')))

I hope this is easy but I a kind of lost on this one. I am also wondering if I maybe need to switch to webpack or something but I am trying to avoid it for now.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...