gpt4 book ai didi

javascript - 无法遍历依赖图

转载 作者:行者123 更新时间:2023-12-04 12:58:07 25 4
gpt4 key购买 nike

我的 Javascript 构建过程最终插入了关键字 require()在文件中。客户端不支持这并导致控制台错误。我已添加 browserify但是,根据其他 SO 答案,我又遇到了另一个错误(如下)。
附加信息:
我在用:

  • gulp 4
  • 节点 (v14.2.0)

  • 错误:
    [16:03:55] Using gulpfile /mnt/c/code/mutationObserver/gulpfile.js
    [16:03:55] Starting 'default'...
    [16:03:55] Starting 'clean'...
    [16:03:55] Finished 'clean' after 10 ms
    [16:03:55] Starting 'html'...
    [16:03:55] Starting 'js'...
    [16:03:55] Starting 'css'...
    [16:03:55] Finished 'html' after 46 ms
    [16:03:55] Finished 'css' after 51 ms
    [16:03:55] 'js' errored after 54 ms
    [16:03:55] Error: Can't walk dependency graph: Cannot find module '/mnt/c/code/mutationObserver/src/js/*.js' from '/mnt/c/code/mutationObserver/src/js/_fake.js'
    required by /mnt/c/code/mutationObserver/src/js/_fake.js
    at /mnt/c/code/mutationObserver/node_modules/resolve/lib/async.js:136:35
    at load (/mnt/c/code/mutationObserver/node_modules/resolve/lib/async.js:155:43)
    at onex (/mnt/c/code/mutationObserver/node_modules/resolve/lib/async.js:180:17)
    at /mnt/c/code/mutationObserver/node_modules/resolve/lib/async.js:15:69
    at FSReqCallback.oncomplete (fs.js:175:21)
    [16:03:55] 'default' errored after 69 ms
    我的整个 Gulpfile.js如下:
    const { series, parallel, watch, src, dest } = require("gulp");
    const plumber = require("gulp-plumber");
    const del = require("del");
    const concat = require("gulp-concat");
    const babel = require("gulp-babel");
    const sass = require("gulp-sass");
    const browserSync = require("browser-sync").create();
    const browserify = require('browserify')
    const source = require('vinyl-source-stream')


    function html() {
    return src("./src/*.html").pipe(dest("./dist"));
    }

    function css() {
    return src("./src/css/style.scss")
    .pipe(plumber())
    .pipe(sass().on("error", sass.logError))
    .pipe(dest("./dist/css"));
    }

    function js() {
    return browserify("./src/js/*.js")
    .bundle()
    .pipe(source("main.js"))
    .pipe(plumber())
    .pipe(
    babel({
    presets: ["@babel/env"],
    plugins: ["@babel/transform-runtime"],
    })
    )
    .pipe(dest("./dist/js"));
    }

    function clean() {
    return del(["./dist"]);
    }

    function watchFor() {
    browserSync.init({
    server: {
    baseDir: "./dist/",
    },
    });

    // first rerun the function that distributed the css files, then reload the browser
    watch("./src/css/**/*.scss").on("change", css);
    watch("./dist/css/*.css").on("change", browserSync.reload);

    // first rerun the function that distributed the javascript files, then reload the browser
    watch("./src/js/*.js").on("change", js);
    watch("./dist/js/*.js").on("change", browserSync.reload);

    // first rerun the function that writes to the dist folder, then reload the browser
    watch("./src/*.html").on("change", html);
    watch("./dist/*.html").on("change", browserSync.reload);
    }

    exports.clean = clean;
    exports.css = css;
    exports.js = js;
    exports.html = html;
    exports.watch = watch;
    exports.default = series(clean, parallel(html, js, css), watchFor);

    最佳答案

    我有同样的错误。这个错误意味着它找不到所需的js文件。确保文件位于“必需”中指定的正确文件夹中,如果它位于同一文件夹中,您可能需要添加 ./。
    browserify main.js -o bundle.js

    Error: Can't walk dependency graph: Cannot find module 'srt' from 'C:\code\html1\main.js'
    在我的 main.js 错误中,我更改了:
    var srt = require('srt');
    至:
    var srt = require('./srt');
    然后它起作用了。

    关于javascript - 无法遍历依赖图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63529556/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com