inxilpro / node-app-root-path

Determine the root path to your project
MIT License
605 stars 29 forks source link

New version broke webpack build with TypeORM #34

Closed balazskoti closed 5 years ago

balazskoti commented 5 years ago

Commit b20b622c20bf9f78b8ab06f9020935843f9a8cc3 broke TypeORM webpack project. (I think it is not TypeORM specific).

I'm using webpack to build my node/typescript project, I am not using yarn at all.

Module not found: Error: Can't resolve 'pnpapi' in 'project\node_modules\app-root-path\lib'
 @ ./node_modules/app-root-path/lib/resolve.js 30:12-29
 @ ./node_modules/app-root-path/lib/app-root-path.js
 @ ./node_modules/app-root-path/index.js
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/driver/mongodb/typings.js
 @ ./node_modules/typeorm/index.js
 @ ./src/engine/components/Database.ts
 @ ./src/engine/configuration/ComponentRegistry.ts
 @ ./src/engine/loaders/ComponentLoader.ts
 @ ./src/Engine.ts
 @ ./src/init.ts

The if (process.versions.pnp) {...} should not activate.

inxilpro commented 5 years ago

Do you get that error when trying to build with webpack? Or when you're running the script?

balazskoti commented 5 years ago

While trying to run the build with webpack. This is my webpack config:

const path = require('path');
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
const webpack = require("webpack");

module.exports = function(env, args){

       /*SOME LOGIC HERE*/

    // final config
    return {

        target: "node",

        entry: './src/init.ts',

        node: {
            __dirname: true
        },

        module: {
            rules: [
                {
                    test: /\.ts$/,
                    use: 'ts-loader',
                    exclude: [/node_modules/]
                }
            ]
        },

        resolve: {
            extensions: ['.tsx', '.ts', '.js'],
            alias: {
                // https://github.com/NodeRedis/node_redis/issues/790
                'hiredis': path.join(__dirname, 'aliases/hiredis.js')
            }
        },

        optimization: {
            minimize: false
        },

        plugins: [

            // replace environment file
            new webpack.NormalModuleReplacementPlugin(/(.*)environments\/environment(\.*)/, function(resource) {
                resource.request = resource.request.replace(/environments\/environment/, `environments/environment.${appProfile}`);
            }),

            //ignore the drivers you don't want. This is the complete list of all drivers -- remove the suppressions for drivers you want to use.
            new FilterWarningsPlugin({
                exclude: [/mongodb/, /*/mssql/,*/ /mysql/, /mysql2/, /oracledb/, /pg/, /pg-native/, /pg-query-stream/, /redis/, /sqlite3/]
            })
        ],

        output: {
            filename: 'bundle.js',
            path: path.resolve(__dirname, 'dist')
        }

    };
};

Btw, I'm looking at typeorm's package json which looks for "app-root-path": "^2.0.1", which looks like it has disappeared from NPM.

inxilpro commented 5 years ago

The 2.2.1 release should fix this.