[英]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.