Reactjs 如何解决使用情感时的汇总构建错误:';默认值';不是由@emotion\memoize\dist\memoize.cjs导出的

Reactjs 如何解决使用情感时的汇总构建错误:';默认值';不是由@emotion\memoize\dist\memoize.cjs导出的,reactjs,typescript,rollupjs,emotion,Reactjs,Typescript,Rollupjs,Emotion,我正在尝试为我们的企业库构建一个标准化的react按钮组件。我希望能够使用@emotion/styled生成样式化的react组件。我们使用rollup作为包生成器,它从typescript传输到esm和commonjs。当我运行构建时,出现以下错误: 错误:节点\u modules\@emotion\memoize\dist\memoize.cjs未导出“默认值” 节点\u modules\@emotion\is-prop-valid\dist\is-prop-valid.esm.js(1:7

我正在尝试为我们的企业库构建一个标准化的react按钮组件。我希望能够使用@emotion/styled生成样式化的react组件。我们使用rollup作为包生成器,它从typescript传输到esm和commonjs。当我运行构建时,出现以下错误:
错误:节点\u modules\@emotion\memoize\dist\memoize.cjs未导出“默认值”
节点\u modules\@emotion\is-prop-valid\dist\is-prop-valid.esm.js(1:7)
1:从“@emotion/memoize”导入memoize

我仍在学习使用汇总和打字脚本构建的细节,因此我无法判断我是否只是做错了什么,或者@emotion库是否存在实际问题

我试过设置:

commonjs({
    include: ['/node_modules/**', '../../../node_modules/**'],
    namedExports: {
        'node_modules/@emotion/memoize/dist/memoize.cjs.js': ['memoize']
    }
})

但两者都不起作用。 我试过安装@emotions的不同版本,从10.0.0到10.0.10,所有版本都会这样。 我也尝试过直接安装@emotion/memoize,但也没用

以下是我的生成设置和代码:

自定义按钮.tsx

从“React”导入React;
从“/自定义按钮道具”导入自定义按钮道具;
从'@emotion/styled'导入styled,{StyledComponent};
从'@enterpriseapi/constants'导入{StyleConstants};
导出类CustomButton扩展React.PureComponent{
公共构造函数(道具:CustomButtonProps){
超级(道具);
}
私有DefaultButton:StyledComponent=styled.button`
高度:2em;
左侧填充:0.75rem;
右侧填充:0.75rem;
${StyleConstants.defaultButton}
`;
public render():React.ReactNode{
如果(此.props.style){
返回(
{this.props.text}
);
}
返回{this.props.text};
}
}
导出默认自定义按钮;
自定义按钮-props.tsx

从'react'导入{MouseEvent,KeyboardEvent,CSSProperties};
导出接口CustomButtonProps{
文本:字符串;
onClick:(事件:MouseEvent | KeyboardEvent)=>void;
风格?:CSSProperties;
}
导出默认CustomButtonProps;
rollup.config.js

import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

export default {
    input: 'src/index.ts',
    output: [
        {
            file: pkg.main,
            format: 'cjs',
            exports: 'named'
        },
        {
            file: pkg.module,
            format: 'es',
            compact: true
        }
    ],
    external: [...Object.keys(pkg.peerDependencies || {})],

    plugins: [
        typescript({
            typescript: require('typescript')
        }),
        resolve(),
        commonjs({
            include: ['/node_modules/**', '../../../node_modules/**']
        })
    ]
};
tsconfig.json

{
    "compilerOptions": {
        "outDir": "./lib/", // path to output directory
        "sourceMap": false, // allow sourcemap support
        "strictNullChecks": true, // enable strict null checks as a best practice
        "module": "es6", // specify module code generation
        "jsx": "react", // use typescript to transpile jsx to js
        "target": "es5", // specify ECMAScript target version
        "allowJs": false, // allow a partial TypeScript and JavaScript codebase
        "strict": true,
        "declaration": true,
        "moduleResolution": "node",
        "esModuleInterop": true,
        "noImplicitAny": true,
        "noImplicitReturns": true,
        "noImplicitThis": true
    },
    "include": ["src"],
    "exclude": ["node_modules", "**/__tests__/*"]
}
package.json

{
    "name": "@custom-component/button",
    "version": "0.0.0",
    "description": "",
    "main": "lib/index.js",
    "types": "lib/index.d.ts",
    "module": "lib/index.esm.js",
    "scripts": {
        "test": "jest --config jestconfig.json --coverage",
        "document": "typedoc --out documentation --hideGenerator --includeDeclarations --exclude \"**/node_modules/**\" src/",
        "compile": "rollup -c",
        "audit": "yarn audit --registry=https://registry.npmjs.org --json > audit-results.json",
        "build": "yarn run clean && yarn run document && yarn run compile",
        "clean": "shx rm -rf lib documentation",
        "prepublishOnly": "yarn run build && yarn version --patch"
    },
    "files": [
        "lib/**/*"
    ],
    "author": "",
    "license": "ISC",
    "devDependencies": {
        "@emotion/core": "^10.0.0",
        "@emotion/styled": "^10.0.0",
        "@types/jest": "^24.0.3",
        "@types/react": "^16.8.8",
        "@typescript-eslint/eslint-plugin": "^1.1.0",
        "@typescript-eslint/parser": "^1.1.0",
        "awesome-typescript-loader": "^5.2.1",
        "eslint": "^5.12.0",
        "jest": "^24.5.0",
        "react": "^16.8.5",
        "rollup": "^1.7.2",
        "rollup-plugin-commonjs": "^9.2.0",
        "rollup-plugin-node-resolve": "^4.0.0",
        "rollup-plugin-typescript2": "^0.20.1",
        "shx": "^0.3.2",
        "ts-jest": "^24.0.0",
        "typedoc": "^0.14.2",
        "typescript": "^3.2.4"
    },
    "peerDependencies": {
        "@types/react": "^16.8.8",
        "react": "^16.8.5"
    },
    "dependencies": {
        "@emotion/core": "^10.0.0",
        "@emotion/styled": "^10.0.0",
        "@enterprise-api/constants": "^0.0.8-beta"
    }
}
我应该能够构建这个组件而没有任何问题,但是我得到了上面的错误


谢谢

试试下面的方法,希望它能奏效

commonjs({
        include: 'node_modules/**',
        namedExports: {
        'node_modules/@emotion/memoize/dist/memoize.cjs.js':['memoize']'
        },
}),

抱歉,我看到我在粘贴文本时没有切换\to/到我尝试的内容。这实际上是我尝试过的事情之一,但没有运气。谢谢。你能清理你的依赖项吗?我可以看到@emotion/core,emotion/styled的重复依赖项。另外,您可以将emotion安装为dependency并尝试重新构建链接,这可能会有所帮助:遵循该问题中的线程帮助我通过将
include:[/node\u modules/]
设置为regex来构建包。但是,当我尝试使用该组件时,我现在收到一个错误,指出memoize_cjs不是内置包中的一个函数。在汇总时有一个开放的错误,尚未解决。你现在必须用丑陋的方式来做进口。
commonjs({
        include: 'node_modules/**',
        namedExports: {
        'node_modules/@emotion/memoize/dist/memoize.cjs.js':['memoize']'
        },
}),