错误"版本"在使用汇总构建时是必需参数

时间:2017-12-26 13:14:06

标签: runtime-error required args rollupjs

我正在使用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$1.BasicSourceMapConsumer (/home/programmersedge/.nvm/versions/node/v6.11.1/lib/node_modules/rollup/dist/rollup.js:15763:22)
    at new SourceMapConsumer$1 (/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参数在我的设置中的位置 要么 我的设置有什么问题。任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

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

这里是问题的解释

  

报告的错误是尝试使用源时发生的错误   报告另一个错误时映射。发生的实际错误是   可能是CANNOT_CALL_NAMESPACE,根据我的理解意味着   您正尝试在导入中调用绑定*的变量。

以及您可以参考的GitHub Issue

答案 1 :(得分:1)

对于遇到这种情况的任何人,现在都有一个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时。