npm start编译失败

时间:2018-12-28 10:26:03

标签: reactjs npm package.json npm-start

这是npm start,运行react-scripts start的问题。拜托,有人可以帮我吗?

我正在尝试在我的应用中使用Swiper,并且在控制台上收到此错误。

!UPDATED:添加了使用滑动器的代码。

Failed to compile.
./node_modules/swiper/dist/js/swiper.esm.bundle.js
Module not found: Can't resolve '/home/lemes/Projects/idealnemoloko-react/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/assertThisInitialized' in '/home/lemes/Projects/idealnemoloko-react/node_modules/swiper/dist/js'

Laso为您提供一个package.json

我祈祷这会有所帮助

package.json

{
  "name": "idealnemoloko-react",
  "version": "0.1.0",
  "private": true,
  "homepage": ".",
  "dependencies": {
    "gh-pages": "^2.0.1",
    "gsap": "^2.0.2",
    "react": "^16.6.0",
    "react-art": "^16.6.1",
    "react-dom": "^16.6.0",
    "react-native": "^0.57.4",
    "react-native-web": "^0.9.6",
    "react-on-images-loaded": "^2.1.9",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.1",
    "swiper": "^4.4.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

我正在使用swiper的文件: 秘方/index.js

this.swiper = new Swiper('.recipes-swiper-container', {
  direction: 'vertical',
  speed: 1000,
  slidesPerView: 1,
  allowTouchMove: false,
  mousewheel: true,
  pagination: {
    el: '.recipes-swiper-pagination',
    clickable: true,
  },
  on: {
    transitionEnd: this.handleSlideTrans
  }
});

main / index.js

 hasLoaded() {
    if(this.state.isLoading === true) {
      this.setState({isLoading: false})

      this.swiper = new Swiper('.swiper-container', {
        direction: 'vertical',
        preventInteractionOnTransition: true,
        speed: 1000,
        autoplay: {
          delay: 5000,
          disableOnInteraction: false,
        },
        slidesPerView: 1,
        initialSlide: this.props.index,
        allowTouchMove: false,
        mousewheel: {
          eventsTarged: '#main-page'
        },
        pagination: {
          el: '.swiper-pagination',
          type: 'bullets',
          clickable: true
        },
      });

      this.swiperInfo = new Swiper('.swiper-container-info', {
        direction: 'vertical',
        preventInteractionOnTransition: true,
        speed: 1000,
        slidesPerView: 1,
        allowTouchMove: false,
        initialSlide: this.props.index
      });

      this.swiper.on('slideNextTransitionStart', () => {
        this.swiperInfo.slideNext();
      });
      this.swiper.on('slidePrevTransitionStart', () => {
        this.swiperInfo.slidePrev();
      });

      var pag = document.getElementsByClassName('swiper-pagination')[0].clientHeight;
      document.getElementById('info-back').style.top = 'calc(50% - ' + pag/window.innerHeight*100/3.25 + 'vh)';
    }
  }

  swiperStart() {
    this.swiper.autoplay.start();
  }

为什么/index.js

this.swiper = new Swiper('.why-swiper-container', {
      direction: 'vertical',
      speed: 1000,
      slidesPerView: 1,
      allowTouchMove: false,
      mousewheel: true,
      pagination: {
        el: '.why-swiper-pagination',
        clickable: true,
      },
      on: {
        transitionEnd: this.handleSlideTrans
      }
    });

1 个答案:

答案 0 :(得分:0)

我认为您需要Swiper

您需要像这样导入Swiper软件包:

import Swiper from 'swiper/dist/js/swiper.js'