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

Tracing fails to detect fs when used in multiple entries with webpack 5 #201

Closed
ijjk opened this issue May 11, 2021 · 0 comments · Fixed by #205
Closed

Tracing fails to detect fs when used in multiple entries with webpack 5 #201

ijjk opened this issue May 11, 2021 · 0 comments · Fixed by #205
Assignees

Comments

@ijjk
Copy link
Member

ijjk commented May 11, 2021

Continuation of #185

When building a Next.js project that reads from the filesystem in multiple pages the webpack output changes and nft fails to detect the needed local files. When only one page reads from the filesystem the webpack output is handled correctly.

Related Next.js issue: vercel/next.js#24700
Provided Next.js reproduction: https://github.com/jacksonhardaker/next-webpack-5-fs-bug

Example output when only one page reads from the filesystem (traces `/data` correctly)
(function() {
var exports = {};
exports.id = 405;
exports.ids = [405];
exports.modules = {

/***/ 34:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "default": function() { return /* binding */ _; },
  "getServerSideProps": function() { return /* binding */ getServerSideProps; }
});

;// CONCATENATED MODULE: external "react/jsx-runtime"
var jsx_runtime_namespaceObject = require("react/jsx-runtime");;
;// CONCATENATED MODULE: external "fs"
var external_fs_namespaceObject = require("fs");;
;// CONCATENATED MODULE: external "path"
var external_path_namespaceObject = require("path");;
var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_namespaceObject);
;// CONCATENATED MODULE: ./pages/index.js




function _({
  text
}) {
  return /*#__PURE__*/(0,jsx_runtime_namespaceObject.jsxs)("div", {
    children: [/*#__PURE__*/jsx_runtime_namespaceObject.jsx("h1", {
      children: "next-webpack-5-fs-bug"
    }), /*#__PURE__*/jsx_runtime_namespaceObject.jsx("p", {
      children: text
    })]
  });
}
function getServerSideProps() {
  const text = (0,external_fs_namespaceObject.readFileSync)(external_path_default().resolve(process.cwd(), 'data/copy.txt'), {
    encoding: 'utf-8'
  });
  return {
    props: {
      text
    }
  };
}

/***/ })

};
;

// load runtime
var __webpack_require__ = require("../webpack-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); }
var __webpack_exports__ = (__webpack_exec__(34));
module.exports = __webpack_exports__;

})();
Example output when only multiple page reads from the filesystem (fails to trace `/data`)
(function() {
var exports = {};
exports.id = 405;
exports.ids = [405];
exports.modules = {

/***/ 474:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": function() { return /* binding */ _; },
/* harmony export */   "getServerSideProps": function() { return /* binding */ getServerSideProps; }
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(282);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(747);
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(622);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_2__);




function _({
  text
}) {
  return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
    children: [/*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("h1", {
      children: "next-webpack-5-fs-bug"
    }), /*#__PURE__*/react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
      children: text
    })]
  });
}
function getServerSideProps() {
  const text = (0,fs__WEBPACK_IMPORTED_MODULE_1__.readFileSync)(path__WEBPACK_IMPORTED_MODULE_2___default().resolve(process.cwd(), 'data/copy.txt'), {
    encoding: 'utf-8'
  });
  return {
    props: {
      text
    }
  };
}

/***/ }),

/***/ 747:
/***/ (function(module) {

"use strict";
module.exports = require("fs");;

/***/ }),

/***/ 622:
/***/ (function(module) {

"use strict";
module.exports = require("path");;

/***/ }),

/***/ 282:
/***/ (function(module) {

"use strict";
module.exports = require("react/jsx-runtime");;

/***/ })

};
;

// load runtime
var __webpack_require__ = require("../webpack-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); }
var __webpack_exports__ = (__webpack_exec__(474));
module.exports = __webpack_exports__;

})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants