Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Module parse failed: Unexpected token (225:12) #41

Open
ndcc5 opened this issue Aug 9, 2021 · 6 comments
Open

Module parse failed: Unexpected token (225:12) #41

ndcc5 opened this issue Aug 9, 2021 · 6 comments

Comments

@ndcc5
Copy link

ndcc5 commented Aug 9, 2021

npm run start

./node_modules/web3-eth-accounts/lib/index.js
Module parse failed: Unexpected token (225:12)
You may need an appropriate loader to handle this file type.
| }
| return signed({
| ...tx,
| chainId: args[0],
| nonce: args[1],

@ndcc5
Copy link
Author

ndcc5 commented Aug 9, 2021

image

@mojtabaahn
Copy link

+1

@amiralisahraei
Copy link

amiralisahraei commented Nov 8, 2021

I have the same problem

@shayanb
Copy link

shayanb commented Nov 12, 2021

What Node version are you using? Try using v9.7.1 (I suggest using nvm for easier switching between Node versions)

@amiralisahraei
Copy link

Thanks for answering but i test this version of node too but nothing changed :(
Has you run this project without any problem ?
@shayanb

@212413616
Copy link

212413616 commented Nov 26, 2021

I am Chinese, my English is not good, please translate the following Chinese

我出现这个问题的原因是因为在vue中使用webpack进行初始化项目,代码中 使用require('web3.js'); 就会报错。
大概原因是因为没有解析到扩展运算符(...),所以只需要让程序解析就好了。

我的解决方法是:在build/webpack.base.conf.js文件中,配置:resolve('你的第三方库路径')

 module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: [resolve('src'), 
          resolve('test'), 
          resolve('node_modules/webpack-dev-server/client'),
         resolve('你的第三方库路径')
        ]
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('img/[name].[hash:7].[ext]')
        }
      },

例如我web3.js出现了问题,我的修改的配置是:

  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: [resolve('src'), resolve('test'),
          resolve('node_modules/webpack-dev-server/client'),
          resolve('node_modules/web3-eth-accounts/lib'),
          resolve('node_modules/web3-core-helpers/lib'),
          resolve('node_modules/web3-core-method/lib'),
          resolve('node_modules/web3-eth-contract/lib')
        ]
      },

然后去修改.babelrc文件:

{
  "presets": [
    "stage-2"
  ]
}

我问题就这样解决了

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants