使用Stripe Checkout时,由于加载程序而导致获得未过期令牌导致错误

时间:2020-10-16 05:27:36

标签: javascript node.js vue.js webpack

我正在尝试将Stripe checkout集成到VueJS应用程序中,但是在应用程序编译时出现以下错误;

ERROR in ./node_modules/stripe/lib/utils.js
Module parse failed: Unexpected token (152:24)
You may need an appropriate loader to handle this file type.
|         opts.auth = args.pop();
|       } else if (utils.isOptionsHash(arg)) {
|         const params = {...args.pop()};
| 
|         const extraKeys = Object.keys(params).filter(
 @ ./node_modules/stripe/lib/stripe.js 44:14-32
 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/app/CMS/eCommerce/Checkout.vue
 @ ./src/app/CMS/eCommerce/Checkout.vue
 @ ./src/routes.js
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8082 webpack/hot/dev-server ./src/main.js

我将以下变量添加到mt Checkout.vue文件中时会发生;

从'stripe'导入Stripe; const stripe = Stripe('MYAPI');

这是我们的webpack文件

var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    filename: 'build.js',
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/'
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'style-loader',
          'css-loader'
        ],
      },
      {
        test: /\.html$/i,
        loader: 'html-loader',
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]',
          outputPath: 'assets/images/'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json']
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true,
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}

任何建议都会很棒。谢谢

1 个答案:

答案 0 :(得分:0)

在我看来./src/app/CMS/eCommerce/Checkout.vue文件中出现了问题。

首先:变量 arg args 是否确实存在?

第二:为了使语法params = {...args.pop()}有效,args必须是对象数组

第三:您有babel配置文件吗?因为我认为您需要babel预设“ @ babel / preset-env”或某些babel插件(例如“ @ babel / plugin-proposal-object-rest-spread”和“ @ babel / plugin-transform-spread”)才能进行babel的转换浏览器的代码...

最小的babel.config.js可能如下所示:

module.exports = api => {
    api.cache(true);

    const presets = [];
    const plugins = [];

    /*
    // If you want to transpile just some syntaxes manually - micromanagement
    plugins.push(
        [ "@babel/plugin-transform-block-scoping" ],
        [ "@babel/plugin-proposal-object-rest-spread" ],
        [ "@babel/plugin-transform-classes" ],
        [ "@babel/plugin-transform-spread" ],
        [ "@babel/plugin-transform-destructuring" ],
        [ "@babel/plugin-transform-for-of" ],
        [ "@babel/plugin-transform-template-literals" ],
        [ "@babel/plugin-transform-arrow-functions", { spec: false } ],
    );
    */
    
    // Or let babel transpile everthing
    presets.push(
        [ "@babel/preset-env" ]
    )

    return {
        presets,
        plugins
    }
}