javascript Firebase/auth导入源Map警告

qmelpv7a  于 2023-05-05  发布在  Java
关注(0)|答案(6)|浏览(99)

我正在使用firebase库v7.15.5构建一个react应用程序,当我导入'firebase/auth'时,它工作正常,但它在终端中向我抛出警告:

WARNING in ./node_modules/@firebase/auth/dist/auth.esm.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:es6\promise\promise] ' file: Error: ENOENT: no such file or directory, open 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:es6\promise\promise] '
 @ ./node_modules/firebase/auth/dist/index.esm.js 1:0-24
 @ ./src/utils/firebase/firebase.ts
 @ ./src/store/actions/appProps/index.ts
 @ ./src/pages/schedule/index.tsx
 @ ./src/components/app/index.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx

WARNING in ./node_modules/@firebase/auth/dist/auth.esm.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:es6\util\arrayiterator] ' file: Error: ENOENT: no such file or directory, open 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:es6\util\arrayiterator] '
 @ ./node_modules/firebase/auth/dist/index.esm.js 1:0-24
 @ ./src/utils/firebase/firebase.ts
 @ ./src/store/actions/appProps/index.ts
 @ ./src/pages/schedule/index.tsx
 @ ./src/components/app/index.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx

WARNING in ./node_modules/@firebase/auth/dist/auth.esm.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:es6\util\makeiterator] ' file: Error: ENOENT: no such file or directory, open 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:es6\util\makeiterator] '
 @ ./node_modules/firebase/auth/dist/index.esm.js 1:0-24
 @ ./src/utils/firebase/firebase.ts
 @ ./src/store/actions/appProps/index.ts
 @ ./src/pages/schedule/index.tsx
 @ ./src/components/app/index.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx

WARNING in ./node_modules/@firebase/auth/dist/auth.esm.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:util\defineproperty] ' file: Error: ENOENT: no such file or directory, open 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:util\defineproperty] '
 @ ./node_modules/firebase/auth/dist/index.esm.js 1:0-24
 @ ./src/utils/firebase/firebase.ts
 @ ./src/store/actions/appProps/index.ts
 @ ./src/pages/schedule/index.tsx
 @ ./src/components/app/index.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx

WARNING in ./node_modules/@firebase/auth/dist/auth.esm.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:util\global] ' file: Error: ENOENT: no such file or directory, open 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:util\global] '
 @ ./node_modules/firebase/auth/dist/index.esm.js 1:0-24
 @ ./src/utils/firebase/firebase.ts
 @ ./src/store/actions/appProps/index.ts
 @ ./src/pages/schedule/index.tsx
 @ ./src/components/app/index.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx

WARNING in ./node_modules/@firebase/auth/dist/auth.esm.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:util\polyfill] ' file: Error: ENOENT: no such file or directory, open 'D:\Projects\DeparturesSchedule\node_modules\@firebase\auth\dist\ [synthetic:util\polyfill] '
 @ ./node_modules/firebase/auth/dist/index.esm.js 1:0-24
 @ ./src/utils/firebase/firebase.ts
 @ ./src/store/actions/appProps/index.ts
 @ ./src/pages/schedule/index.tsx
 @ ./src/components/app/index.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx
Child html-webpack-plugin for "index.html":
     1 asset
    Entrypoint undefined = index.html
       4 modules
i 「wdm」: Compiled with warnings.

这是文件的代码,我在其中初始化firebase模块:

import app from 'firebase/app';
import 'firebase/database';
import 'firebase/auth';

const config = {
  apiKey: process.env.API_KEY,
  authDomain: process.env.AUTH_DOMAIN,
  databaseURL: process.env.DB_URL,
  storageBucket: process.env.STORAGE_BUCKET,
};

app.initializeApp(config);

const database = app.database();
const auth = app.auth();

export { database, auth };

已尝试删除node_modules并全部重新安装,但无法解决问题。也许我应该以不同的方式导入它,或者配置webpack或tsconfig?我不知道。
谢谢你的帮助。

hwazgwia

hwazgwia1#

如果你绝对需要source-maps(我不认为你真的需要,因为你的解决方案是禁用它们),你可以为firebase添加一个排除规则(或者只是firebase/auth)。示例(自行构建):

{
    enforce: "pre",
    test: /\.js$/,
    loader: "source-map-loader",
    exclude: /node_modules\/@firebase/ //to exclude firebase from source-map
    exclude: /node_modules\/@firebase\/auth/ //to just exclude firebase auth from source-map
  },
  • 注意:* 仅使用上述排除规则之一
qc6wkl3g

qc6wkl3g2#

如果你不想再看到此警告,一个可能的解决方案是添加此修复编辑文件node_modules/react-scripts/config/webpack.config.js,并将其粘贴在行性能之后:假的,

ignoreWarnings: [
      // Ignore warnings raised by source-map-loader.
      // some third party packages may ship miss-configured sourcemaps, that interrupts the build
      // See: https://github.com/facebook/create-react-app/discussions/11278#discussioncomment-1780169
      /**
       *
       * @param {import('webpack').WebpackError} warning
       * @returns {boolean}
       */
      function ignoreSourcemapsloaderWarnings(warning) {
        return (
          warning.module &&
          warning.module.resource.includes('node_modules') &&
          warning.details &&
          warning.details.includes('source-map-loader')
        );
      },
    ],

我在www.example.com上找到了这个https://github.com/facebook/create-react-app/pull/11752#issuecomment-1146687183

bmp9r5qi

bmp9r5qi3#

升级Firebase版本到9为我们修复了它。
注意,必须更新才能使用compat包:

import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
4xrmg8kj

4xrmg8kj4#

当我调查这些警告时,我注意到其中一些提到了polyfills(尽管不是全部)。旧的webpack版本默认包含node.js核心模块的polyfill。webpack 5不是这样的。这可能与这些警告有关。
参考:https://github.com/facebook/create-react-app/issues/11756
在我的例子中,使用webpack 4而不是webpack 5摆脱了警告,并没有破坏任何东西。这可能是一个解决方案,只要你的代码不需要网页5+。
如果您想尝试此解决方案,您需要:
1.从package.json中删除以下依赖项:“react-scripts”:“5.0.0”,(您的版本可能更高)
1.将以下依赖项添加到package.json:“react-scripts”:“4.0.3”,
1.删除node_modules文件夹
1.运行npm install

wlzqhblo

wlzqhblo5#

首先,转到“Storage”,https://console.firebase.google.com/project/
选择项目名称
然后转到存储
然后
规则选项卡和更改允许读、写:如果为假,则为真;如下面所示。

rules_version = '2';
service firebase.storage {
    match /b/{bucket}/o {
        match /{allPaths=**} {
            allow read, write: if true;
    }
  }
}

欲了解更多信息,请参阅图片

iugsix8n

iugsix8n6#

通过从webpack.config中删除这些代码行解决了这个问题

{
    enforce: "pre",
    test: /\.js$/,
    loader: "source-map-loader"
  },

相关问题