我试图让ScrollMagic使用ES2015导入和React。我收到此错误:
ERROR in ./~/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js
Module not found: Error: Cannot resolve module 'TimelineMax' in /Users/dillonraphael/Desktop/marbleshark_landingpage/node_modules/scrollmagic/scrollmagic/uncompressed/plugins
@ ./~/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js 31:2-61
这就是我导入所有内容的方式。
import {gsap, TimelineMax, TweenMax} from 'gsap';
import ScrollMagic from 'ScrollMagic';
require('scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap');
答案 0 :(得分:5)
使用此import
语句对我有用:
import * as ScrollMagic from 'scrollmagic'
使用npm install scrollmagic
安装软件包后。
答案 1 :(得分:0)
我就是这样做的:
的WebPack:
config.resolve.alias = {
ScrollMagic: path.resolve('node_modules', 'scrollmagic/scrollmagic/uncompressed/ScrollMagic.js'),
};
componentDidMount() {
const ScrollMagic = require('ScrollMagic');
const controller = new ScrollMagic.Controller({ globalSceneOptions: { triggerHook: 0 } });
}