Skip to content

fix(server-renderer): provide __filename to vm for webpack #12242

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

privatenumber
Copy link
Contributor

@privatenumber privatenumber commented Aug 24, 2021

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:
Reasons:

  • The virtual module is wrapped here, which adds the wrapper:

        (function(exports, require, module, __filename, __dirname) {
        // Module code actually lives in here
        });

    However, __filename and __dirname are not provided:

    compiledWrapper.call(m.exports, m.exports, r, m)

  • When Webpack 5 builds for a Node.js target, it uses the following code. Because __filename is undefined, require("url").pathToFileURL(__filename) breaks. Notice this is with both optimization.splitChunks and optimization.runtimeChunk set to false, and there are no chunks -- proven by the installedChunks object below.

    /******/ 	/* webpack/runtime/require chunk loading */
    /******/ 	(() => {
    /******/ 		__webpack_require__.b = require("url").pathToFileURL(__filename);
    /******/ 		
    /******/ 		// object to store loaded chunks
    /******/ 		// "1" means "loaded", otherwise not loaded yet
    /******/ 		var installedChunks = {
    /******/ 			"main": 1
    /******/ 		};
    /******/ 		
    /******/ 		// no on chunks loaded
    /******/ 		
    /******/ 		var installChunk = (chunk) => {
    /******/ 			var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;
    /******/ 			for(var moduleId in moreModules) {
    /******/ 				if(__webpack_require__.o(moreModules, moduleId)) {
    /******/ 					__webpack_require__.m[moduleId] = moreModules[moduleId];
    /******/ 				}
    /******/ 			}
    /******/ 			if(runtime) runtime(__webpack_require__);
    /******/ 			for(var i = 0; i < chunkIds.length; i++)
    /******/ 				installedChunks[chunkIds[i]] = 1;
    /******/ 		
    /******/ 		};
    /******/ 		
    /******/ 		// require() chunk loading for javascript
    /******/ 		__webpack_require__.f.require = (chunkId, promises) => {
    /******/ 			// "1" is the signal for "already loaded"
    /******/ 			if(!installedChunks[chunkId]) {
    /******/ 				if(true) { // all chunks have JS
    /******/ 					installChunk(require("./" + __webpack_require__.u(chunkId)));
    /******/ 				} else installedChunks[chunkId] = 1;
    /******/ 			}
    /******/ 		};
    /******/ 		
    /******/ 		// no external install chunk
    /******/ 		
    /******/ 		// no HMR
    /******/ 		
    /******/ 		// no HMR manifest
    /******/ 	})();
    /******/ 	

    The error message:

    TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
       at validateString (internal/validators.js:124:11)
       at Object.resolve (path.js:980:7)
       at Object.pathToFileURL (internal/url.js:1411:25)
       at main.js:45690:51
       at main.js:45728:13
       at Object.<anonymous> (main.js:45800:12)
       at evaluateModule (/vue-server-renderer/build.dev.js:9351:21)
       at /vue-server-renderer/build.dev.js:9409:18
       at new Promise (<anonymous>)
       at /vue-server-renderer/build.dev.js:9401:14
       at Object.renderToString (/vue-server-renderer/build.dev.js:9577:9)
       at /vue-just-ssr/lib/init-server.js:41:39
       at call (/connect/index.js:239:7)
       at next (/connect/index.js:183:5)
       at middleware (/webpack-hot-middleware/middleware.js:38:48)
       at call (/connect/index.js:239:7) {
    code: 'ERR_INVALID_ARG_TYPE'
    }
    
@privatenumber
Copy link
Contributor Author

FYI this PR seems to have been closed when moved to "Done", but not merged

@privatenumber privatenumber reopened this Nov 4, 2021
@lzxb
Copy link
Contributor

lzxb commented Jan 18, 2022

When is this expected to be released

@privatenumber
Copy link
Contributor Author

Not sure if there's a target date but it's in the 2.6.15 project so you can see how much work needs to be done before it's released.

@privatenumber
Copy link
Contributor Author

@posva
This may have been overlooked. Any chance it can be revisited & released?

@niksy
Copy link

niksy commented Jul 17, 2022

Also looking for this. Is there any possibility to have this included in 2.7.x release?

@gggogogo
Copy link

+10086. it can be released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants