用TSUP/ESBUILD构建的软件包可以在React-Scripts应用程序中查找“ React”
我有一个使用eSbuild
构建的NPM软件包,该软件包在react> react-scripts
应用程序中使用。我在软件包上运行一个构建,并在React-Scripts应用程序中的/node_modules
手动复制和粘贴构建文件夹,这是由于volta和npm-link的问题。
当我运行应用程序时,我会在NPM软件包代码上下文中获得错误:4 Uncluck typeError:Undefined不是函数
它找不到从React导入的createContext
。
import { createContext } from 'react';
const EventContext = createContext();
这是我的npm软件包的tsup.config.js文件:
import { sassPlugin } from '@es-pack/esbuild-sass-plugin';
import { defineConfig } from 'tsup';
export default defineConfig({
entry: ['src/index.js'],
splitting: true,
sourcemap: true,
clean: true,
dts: true,
format: ['esm'],
target: 'es2020',
bundle: true,
esbuildPlugins: [sassPlugin()],
});
这些是我在NPM软件包中的依赖关系和同行依赖性,
"peerDependencies": {
"classnames": ">=2.0.0 <3.0.0",
"prop-types": ">=15.0.0 <16.0.0",
"react": ">=17.0 <18.0.0",
"react-dom": ">=17.0 <18.0.0"
},
"dependencies": {
"@xstate/react": "^2.0.1",
"focus-trap": "^6.6.1",
"react-share": "^4.4.0",
"xstate": "^4.30.6"
},
是否存在反式订阅构建设置与ESBUILD软件包输出之间的问题?我的应用程序具有 。为什么我的NPM软件包代码导入无法反应?
I have an npm package that I built using esBuild
that I am using in a react-scripts
application. I'm running a build on the package and manually copying and pasting the build folder to /node_modules
in the react-scripts app due to an issue with volta and npm-link.
When I run my application I get an error in my npm package code Context.js:4 Uncaught TypeError: undefined is not a function
it's not finding createContext
that's imported from react.
import { createContext } from 'react';
const EventContext = createContext();
Here is my tsup.config.js file for the npm package:
import { sassPlugin } from '@es-pack/esbuild-sass-plugin';
import { defineConfig } from 'tsup';
export default defineConfig({
entry: ['src/index.js'],
splitting: true,
sourcemap: true,
clean: true,
dts: true,
format: ['esm'],
target: 'es2020',
bundle: true,
esbuildPlugins: [sassPlugin()],
});
And these are my dependencies and peerDependencies in the npm package
"peerDependencies": {
"classnames": ">=2.0.0 <3.0.0",
"prop-types": ">=15.0.0 <16.0.0",
"react": ">=17.0 <18.0.0",
"react-dom": ">=17.0 <18.0.0"
},
"dependencies": {
"@xstate/react": "^2.0.1",
"focus-trap": "^6.6.1",
"react-share": "^4.4.0",
"xstate": "^4.30.6"
},
Is there an issue between the react-scripts build setup and the esBuild package output? My application has [email protected] installed and works fine without my npm package installed. Why can't my npm package code import react?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
从“ react”;
导入到您正在使用的文件的顶部。向所有人。You need to add
import React from 'react';
to the top of the files you are using react . To all of them.