mobxjs / mobx-react

React bindings for MobX
https://mobx.js.org/react-integration.html
MIT License
4.85k stars 350 forks source link

Uncaught ReferenceError: $mobx is not defined #880

Closed hongrunhui closed 4 years ago

hongrunhui commented 4 years ago

Hi, I have a question: I imported mobx-react in my project, but error like this:

image image

I searched to solve this problem and found the code in mobxreact.esm.js

import { Reaction, _allowStateChanges, _allowStateReadsStart, _allowStateReadsEnd, $mobx, createAtom, untracked, isObservableMap, isObservableObject, isObservableArray, observable } from 'mobx';

but the file whitch built from webpack like this:

image

So I got the error

my webpack config:

const path = require('path');
const webpackConfig =  {
    mode: 'development',
    // devtool: 'cheap-module-eval-source-map',
    // devtool: 'eval-source-map',
    devtool: 'source-map',
    entry: {
        app: '../index.js',
    },
    output: {
        path: path.resolve(__dirname, '../dist'),
        library: 'akali',
        filename: '[name].js',
        libraryTarget: 'umd',
        umdNamedDefine: true,
        globalObject: 'this',
        publicPath: 'dist'
    },
    resolve: {
        extensions: ['.js', '.jsx','.tsx', '.ts']
    },
    module: {
        rules: [
            {
                test: /\.(js|ts|tsx|jsx)$/,
                use: [
                    {
                        loader: 'babel-loader'
                    },
                    {
                        loader: 'ts-loader',
                        options: {
                            transpileOnly: true
                        }

                    }
                ]
            },
            {
                test: /\.less|\.css$/,
                use: [
                    {
                        loader: 'style-loader'
                    },
                    {
                        loader: 'css-loader'
                    },
                    {
                        loader: 'less-loader'
                    }
                ]
            },
            {
                test: /\.(png|jpg|jpeg|gif|svg)$/i,
                loader: 'url-loader',
                options: {
                    limit: 100 * 8192,
                    name: 'image/[name].[hash:8].[ext]'
                }
            },
        ]
    },
};
module.exports = webpackConfig;

my tsconfig.json:

{
    "compilerOptions": {
        "module": "esnext",
        "moduleResolution": "node",
        "outDir": "./dist/",
        "noImplicitAny": true,
        "target": "esnext",
        "jsx": "react",
        "sourceMap": true,
        "lib": ["dom", "es5", "es6", "es7", "scripthost"],
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "skipLibCheck": true,
        "strict": true,
        "allowJs": true,
        "baseUrl": "./"
    }
}
danielkcz commented 4 years ago

Please, setup repo with reproduction, hard to say like this.

mweststrate commented 4 years ago

You will need to update Mobx most probably

On Sat, 27 Jun 2020, 07:56 Daniel K., notifications@github.com wrote:

Please, setup repo with reproduction, hard to say like this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mobxjs/mobx-react/issues/880#issuecomment-650509714, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBDBS547COBXRQPKGEDRYWJYXANCNFSM4OJ4DLZQ .

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.