@ligisayan

Как пофиксить ERROR in wpapi.js Module parse failed You may need an appropriate loader to handle this file type?

Всем привет!
При установке npm модулей получаю ошибку при сборке webpack
ERROR in ./~/wpapi/wpapi.js Module parse failed: C:\Users...\decoupled\node_modules\wpapi\wpapi.js Unexpected token (235:2) You may need an appropriate loader to handle this file type. | WPAPI.prototype.url = function( url ) { |
return new WPRequest( { | ...this._options, |
endpoint: url, | } ); @ ./src/lib/config.js 1:0-26 @ ./src/components/Menu/Index.js @ ./src/App.js @ multi (webpack)-dev-server/client?https://localhost:9000 ./src/App.js webpack: Failed to compile.


node -v v16.14.2, npm -v 8.5.5

package.json
{
  "name": "node-wpapi",
  "version": "1.0.0",
  "description": "Example of using the Node JavaScript WP API Client  - https://github.com/WP-API/node-wpapi",
  "main": "src/index.js",
  "scripts": {
    "start": "webpack-dev-server --https",
    "build": "webpack --config webpack.config.js"
  },
  "keywords": [],
  "author": "Zac Gordon",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-core": "^6.22.1",
    "babel-loader": "^6.2.10",
    "babel-preset-es2015": "^6.22.0",
    "uglifyjs-webpack-plugin": "^0.1.4",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.4.1"
  },
  "dependencies": {
    "wpapi": "^1.0.3"
  }
}


webpack.config.js
var path = require( 'path' );
var UglifyJSPlugin = require( 'uglifyjs-webpack-plugin' );

module.exports = {
    entry: [ './src/App.js' ],
    output: {
        filename: 'bundle.min.js',
        path: path.resolve( __dirname, 'dist' )
    },
    devtool: "cheap-eval-source-map",
    devServer: {
        port: 9000,
        contentBase: path.join( __dirname, "dist" )
    },
    module: {
        rules: [{
            test: /\.js$/,
            exclude: /(node_modules)/,
            use: [ {
                loader: 'babel-loader',
                options: {
                    presets: [ [ 'es2015', { modules: false } ] ]
                }
            } ]
        }]
    },
    plugins: [
        new UglifyJSPlugin()
    ]
};
  • Вопрос задан
  • 40 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы