简体   繁体   English

Create-react-app不允许从node_modules导入component.js吗?

[英]Create-react-app doesn't allow import component.js from node_modules?

I received error when try to import { PrimaryButton } from 'my-npm-modules/src/button' ( which is a flowtype src jsx file with extension .js)? 尝试import { PrimaryButton } from 'my-npm-modules/src/button' (这是扩展名为.js的流类型src jsx文件) import { PrimaryButton } from 'my-npm-modules/src/button'时收到错误?

Is it because the create-react-app have config to NOT do flowtype processing for files in node_modules? 是因为create-react-app的配置不对node_modules中的文件进行流类型处理吗?

Module parse failed: /Users/me/live-demo/node_modules/my-npm-modules/src/button.js Unexpected token (2:35)
You may need an appropriate loader to handle this file type.
| //@flow
| import React from 'react';
| export function PrimaryButton(props: {
|     text: string;
|     onClick: ()=>void

When I put the button.js inside the live-demo project, it works fine. 当我将button.js放入live-demo项目中时,它可以正常工作。

It seems it did exclude the node_modules folder for performance reason. 似乎出于性能原因,它确实排除了node_modules文件夹。

So I endup compile the flow-typed jsx --> normal js files, and provided js.flow at the same output folder for sake of consumer flowtype support. 因此,我最终编译了流程类型的jsx->普通js文件,并在同一输出文件夹中提供了js.flow,以支持消费者流程类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建反应应用程序git push node_modules - create-react-app git pushing node_modules 来自 index.html 的 node_modules 中的引用文件夹(create-react-app) - Reference folder in node_modules from index.html (create-react-app) (Create-React-App)找不到模块:您试图导入项目之外的 /node_modules/console-browserify/index.js - (Create-React-App) Module not found: You attempted to import /node_modules/console-browserify/index.js which falls outside of the project 无法在node_modules中创建React组件并在应用程序中使用它 - Can't create a React component in node_modules and use it in an application create-react-app eslint问题,因为更高级别的文件夹包含另一个包含node_modules的应用程序 - create-react-app eslint issue due to higher level folder containing another app with node_modules in it npx create-react-app my-app 创建后删除已安装的 node_modules 包? - npx create-react-app my-app deleting installed node_modules package after creating? 未复制将 create-react-app 推送到 github node_modules 文件夹 - Pushing create-react-app to github node_modules folder has not been copied 有没有办法复制 node_modules 而不是每次都为 create-react-app 安装它们? - Is there a way to copy node_modules instead of installing them for create-react-app every time? 编辑包是 node_modules 在 create-react-app 项目中没有影响 - Editing package is node_modules has no effect in create-react-app project 通过运行npm install create-react-app创建的node_modules文件夹有什么用? - What for is the node_modules folder that is created by running npm install create-react-app for?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM