Search code examples
javascripttypescriptrollupjs

Problems with rollupjs configuration


When building my TypeScript project (all node modules are up to date) with the following configuration I get a error message called "Error: When building multiple chunks, the output.dir option must be used, not output.file."

Can anyone help? Thanks.

// [EDIT: I've simplified this configuration as the original
//  one caused some misunderstandings]

// rollup.config.js
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import typescript from 'rollup-plugin-typescript2'
import { uglify } from 'rollup-plugin-uglify'
import gzip from 'rollup-plugin-gzip'

export default {
  input: 'src/main/my-project.ts',

  output: {
    file: 'dist/my-project.umd.production.js',
    format: 'umd',
    name: 'MyProject', 
    sourcemap: false,

    globals: {
      'react': 'React'
    }
  },

  external: ['react'],

  plugins: [
    resolve(),
    commonjs(),
    typescript({
      exclude: 'node_modules/**'
    }),
    uglify(),
    gzip()
  ]
}

This is my tsconfig.json in case it may be important. The build script is started by rollup --c rollup.config.js:

{
  "compilerOptions": {
    "target": "ES5",
    "jsx": "react",
    "allowSyntheticDefaultImports": true,
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "downlevelIteration": true,
    "sourceMap": true,
    "lib": ["es5", "es6", "dom"],
    "esModuleInterop": true,
    "baseUrl": ".",

    "typeRoots": [
      "node_modules/@types"
    ],

    "types": [
      "node", "react", "react-dom", "mocha", "chai"
    ]
  },
  "files": [
    "src/main/my-project.ts"
  ],

  "include": [
    "./src/**/*.ts*"
  ]
}

Solution

  • It seems that the configuration wasn't the problem, but there was still something wrong with the versions of my node modules.

    After I did the following, everything worked fine again:

    > ncu -u
    > npm update
    > npm install