rollup | 오류 해결 Error:'__moduleExports' is not exported by xxxx

2038 단어 rollup
공식 해명

Error: "[name] is not exported by [module]"


Occasionally you will see an error message like this:
'foo' is not exported by bar.js (imported by baz.js)
Import declarations must have corresponding export declarations in the imported module. For example, if you have import a from './a.js' in a module, and a.js doesn't have an export default declaration, or import {foo} from './b.js' , and b.js doesn't export foo , Rollup cannot bundle the code.
This error frequently occurs with CommonJS modules converted by rollup-plugin-commonjs, which makes a reasonable attempt to generate named exports from the CommonJS code but won't always succeed, because the freewheeling nature of CommonJS is at odds with the rigorous approach we benefit from in JavaScript modules. It can be solved by using the namedExports option, which allows you to manually fill in the information gaps.
commonjs의 일부 특성 때문에, 어떤 파일의 변수 내보내기를 명시적으로 지적해야 합니다.
예:
(나의 react 프로젝트)
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import json from 'rollup-plugin-json'

export default {
  input: './lib/main.js',
  output: {
    file: 'build/bundle.min.js',
    format: 'iife',
    name: 'saber2pr',
    banner: `var process = {
      env: {
        NODE_ENV: 'production'
      }
    }`
  },
  watch: {
    include: 'lib/**'
  },
  plugins: [resolve(), commonjs({
    'namedExports': {
      './lib/main.js': ['__moduleExports']
    }
  }), json()]
}

 
이 중에서commonjs 플러그인은 옵션을 설정했습니다./lib/main.js 파일의 내보내기 변수 __moduleExports.
namedExports 구성 항목의 형식:
Options.namedExports?: {
    //  :[ ]
    [key: string]: string[];
}

//  , ( )。

 
그리고 rollup-c를 다시 실행합니다.

좋은 웹페이지 즐겨찾기