使用汇总构建时错误 "version" 是必需的参数

Error "version" is a required argument while building with rollup

我正在使用 rollup 来捆绑我的项目。

开始时,一切正常,但我不知道我在配置中更改了什么,我开始在 运行 rollup -c.

上收到此错误
[!] Error: "version" is a required argument.
Error: "version" is a required argument.
    at Object.getArg (/home/programmersedge/.nvm/versions/node/v6.11.1/lib/node_modules/rollup/dist/rollup.js:14625:11)
    at SourceMapConsumer.BasicSourceMapConsumer (/home/programmersedge/.nvm/versions/node/v6.11.1/lib/node_modules/rollup/dist/rollup.js:15763:22)
    at new SourceMapConsumer (/home/programmersedge/.nvm/versions/node/v6.11.1/lib/node_modules/rollup/dist/rollup.js:15491:7)
    at Module.getOriginalLocation (/home/programmersedge/.nvm/versions/node/v6.11.1/lib/node_modules/rollup/dist/rollup.js:16925:16)
    at Module.error (/home/programmersedge/.nvm/versions/node/v6.11.1/lib/node_modules/rollup/dist/rollup.js:16942:26)
    at CallExpression.bindNode (/home/programmersedge/.nvm/versions/node/v6.11.1/lib/node_modules/rollup/dist/rollup.js:12326:17)
    at CallExpression.bind (/home/programmersedge/.nvm/versions/node/v6.11.1/lib/node_modules/rollup/dist/rollup.js:11415:8)
    at eachChild.child (/home/programmersedge/.nvm/versions/node/v6.11.1/lib/node_modules/rollup/dist/rollup.js:11433:34)
    at keys.forEach.key (/home/programmersedge/.nvm/versions/node/v6.11.1/lib/node_modules/rollup/dist/rollup.js:11450:5)
    at Array.forEach (native)

这是我的 rollup.config.js

import resolve      from 'rollup-plugin-node-resolve'
import babel        from 'rollup-plugin-babel'
import filesize     from 'rollup-plugin-filesize'
import typescript   from 'rollup-plugin-typescript2'
import commonjs     from 'rollup-plugin-commonjs'
import postcss      from 'rollup-plugin-postcss-modules'
import autoprefixer from 'autoprefixer'
import sass         from "node-sass"

const preprocessor = (content, id) => new Promise((resolve, reject) => {
    sass.render({
        file: id,
        sourceMap: "string",
        sourceComments: true,
        sourceMapContents: true,
        outputStyle: "compressed"
    },(err, result) => {
        if (err) {
            return reject(err);
        }
        resolve({code: result.css.toString()});
    });
});

export default {
    input: 'src/index.ts',
    output: {
        file: 'lib/index.js',
        format: 'umd',
        globals: {
            ...
        },
        sourcemap: true,
    },
    external: [
        ...
    ],
    plugins: [ 
        resolve(),  
        postcss({
            preprocessor,
            plugins: [
                autoprefixer(),
            ],
            extensions: ['.scss'],
            writeDefinitions: true,
            postcssModulesOptions: {
                generateScopedName: '[name]__[local]___[hash:base64:5]'
            }
        }),
        typescript({
            tsconfigOverride: {
                compilerOptions: {
                    declaration: true,
                    moduleResolution: "node"
                }
            },
            rollupCommonJSResolveHack: true,
            abortOnError: false,
            typescript: require('typescript'),
        }),
        commonjs(),   
        babel({
            exclude: 'node_modules/**'
        }),
        filesize()
    ],
    watch: {
        include: 'src/**'
    }
  };

我无法弄清楚 version 参数在我的设置中应该放在哪里 要么 我的设置有什么问题。有人可以帮我吗?

无论如何我解决了这个问题。

这里是问题的解释

The reported error is an error that occurs when trying to use a source map when reporting another error. The actual error that occurs is probably CANNOT_CALL_NAMESPACE, which from my understanding means that you're trying to call a variable to which you bound * in an import.

这里是GitHub Issue你可以参考。

对于遇到此问题的任何人,现在有一个带有修复程序的公开 PR:

https://github.com/rollup/rollup/pull/2012

此外,对于很多人来说,一旦这个问题得到解决,就会揭示真正的问题:无法调用命名空间

我在 its own Rollup issue 中找到了解决方法(在 TypeScript 中出现):

import * as something_ from 'something';
const something: typeof something_ = something;
// Now you can use `soemthing` as usual

这仅在通过 Rollup 使用 TypeScript 时发生,而不是在 运行 tsc 直接使用时发生。