-2

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*"
  ]
}
Adriaan
  • 17,741
  • 7
  • 42
  • 75
Natasha
  • 516
  • 7
  • 24
  • Is there something you don't understand about the error message? – jhpratt Jan 14 '19 at 05:33
  • Obviously, otherwise I would not have asked. The error is not because of that "configs" array, if that's what you mean (if I'll replace with "export default configs[0]" then I get the same error) – Natasha Jan 14 '19 at 05:36
  • @jhpratt I've simplified the "rollup.config.js" a bit, maybe now you may better see the problem... – Natasha Jan 14 '19 at 05:55
  • As indicated by the error, you're producing multiple files. You have to give it a directory, not a file, as output. – jhpratt Jan 14 '19 at 05:56
  • After I've simplified the configuration I still got that error message (by the way, I use a similar configuration in another projects, things are working there) – Natasha Jan 14 '19 at 05:59
  • If I remove those "uglify" and "gzip" lines then the script does only generate one output file. I do NOT get the error message then. Nevertheless - a similar configuration works perfectly fine in another project of mine (btw: problems occured when updating rollup to version 1.x). – Natasha Jan 14 '19 at 06:24

3 Answers3

1

I had a similar issue and as a fix I needed to specify the output module in package.json

{
 ...
 "module": "./dist/index.esm.js",
 ...
}

And it's aligned with the rollup config:

output: [
      { file: pkg.main, format: 'cjs' },
      { file: pkg.module, format: 'esm' },
    ]
devHichri
  • 11
  • 2
0

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
Adriaan
  • 17,741
  • 7
  • 42
  • 75
Natasha
  • 516
  • 7
  • 24
0

For all those how are still struggling to get this issue fixed and you are using dynamic imports in the component than you should add inlineDynamicImports: true just above output object

Saad khan
  • 1
  • 1