import from base component can't find variable

前端 未结 1 1851
梦毁少年i
梦毁少年i 2021-01-23 17:51

I have created one BaseComponent which will be extended in all other components :

import React, { Component } from \'react\'
import { ScrollView, Text, Image, Vi         


        
相关标签:
1条回答
  • 2021-01-23 18:21

    In Nodejs each file is a treated as a module, that has its own scope of variables. When you import variable into file say React or ScrollView for example, you add this variable to the module scope, but not to the global scope.

    In case of webpack you can use ProvidePlugin to a few imports as global

    new webpack.ProvidePlugin({
      React: 'react' // ReactJS module name in node_modules folder
    })
    

    After that you are able to skip importing these variables variable in all of your modules as webpack will do it itself handle it whereever needed.

    0 讨论(0)
提交回复
热议问题