Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Error Cannot create property 'context' on string 'Error generating AST' #1064

Closed
liqiangsu opened this issue Aug 26, 2019 · 5 comments · Fixed by #1088
Closed

[BUG]: Error Cannot create property 'context' on string 'Error generating AST' #1064

liqiangsu opened this issue Aug 26, 2019 · 5 comments · Fixed by #1088

Comments

@liqiangsu
Copy link

Describe the bug
The migrate failed with the following message:

>npx webpack-cli migrate webpack.config.js .
npx: installed 1 in 1.926s
Path must be a string. Received undefined
null

 ✖ ︎Migration aborted due to some errors: 

TypeError: Cannot create property 'context' on string 'Error generating AST'
    at tasks.then.catch.error (\node_modules\listr\index.js:112:19)
    at <anonymous>
  × Reading webpack config
    Migrating config to newest version

To Reproduce

>npx webpack-cli migrate webpack.config.js

Screenshots
The version:
@webpack-cli/migrate@0.1.8
The webpack.config.js

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require("path")
var WWW_DIR = path.resolve(__dirname, 'wwwroot');

module.exports = {
    context: __dirname,
    devtool: debug ? "inline-sourcemap" : false,
    entry: "./wwwroot/js/scripts.jsx",
    output: {
        path: __dirname + "/wwwroot/js",
        filename: "scripts.min.js"
    },
    module: {
        loaders: [{
                test: /\.js?/,
                loader: "babel-loader",
                query: {
                    presets: ["react", "es2015", "stage-2"]
                }
            },
            {
                test: /\.json$/,
                loader: 'json-loader'
            }
        ]
    },
    resolve: {
        extensions: ['.js', '.jsx']
    },
    plugins: debug ? [] : [
        new webpack.DefinePlugin({
            "process.env": {
                NODE_ENV: JSON.stringify("production")
            }
        }),
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.optimize.UglifyJsPlugin({ parallel: true, mangle: true, sourcemap: false }),
    ],
};

Please paste the results of webpack-cli info here, and mention other relevant information

  System:
    OS: Windows 10
    CPU: (12) x64 Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz
  Binaries:
    Yarn: 1.17.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.11.2 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    webpack: ^4.39.2 => 4.39.2
    webpack-cli: ^3.3.7 => 3.3.7
    webpack-dev-server: ^3.8.0 => 3.8.0
@kowsheek
Copy link

👍 Having the same issue, with similar kind of set up.

@evenstensberg
Copy link
Member

I think this needs a bit work, leaving it open as good first contribution and needs investigation because it needs to be debugged first. Which version are you migrating from/to?

@evenstensberg evenstensberg changed the title Error Cannot create property 'context' on string 'Error generating AST' [BUG]: Error Cannot create property 'context' on string 'Error generating AST' Sep 20, 2019
@ohana54
Copy link
Contributor

ohana54 commented Oct 2, 2019

Same thing happened to me, added some console logs and got the original message:
TypeError: jscodeshift_1.default is not a function
I think jscodeshift doesn't export a default function, that's why it happens.

@evenstensberg
Copy link
Member

Could you open a PR?

@ohana54
Copy link
Contributor

ohana54 commented Oct 2, 2019

I don't know what the right solution is. Shouldn't it not work for everyone? Or is it a specific environment issue?
I see that the import was changed from a require call to a default import call in #834
I'll create a PR anyway to import it correctly and we can continue the discussion there

ohana54 added a commit to ohana54/webpack-cli that referenced this issue Oct 2, 2019
jscodeshift doesn't expose a default import
evenstensberg added a commit that referenced this issue Oct 2, 2019
Fix jscodeshift import (fixes #1064)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants