vike 0.4.153-commit-3e842bb → 0.4.153-commit-e631897

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +15 -7
  2. package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +2 -1
  3. package/dist/cjs/node/plugin/shared/loggerNotProd.js +4 -5
  4. package/dist/cjs/node/plugin/shared/loggerVite.js +3 -0
  5. package/dist/cjs/node/prerender/runPrerender.js +17 -2
  6. package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +0 -4
  7. package/dist/cjs/node/runtime/renderPage/logHintForCjsEsmError/errors.js +20 -0
  8. package/dist/cjs/node/runtime/renderPage/logHintForCjsEsmError.js +326 -0
  9. package/dist/cjs/node/runtime/renderPage/loggerProd.js +9 -1
  10. package/dist/cjs/node/runtime/utils.js +2 -1
  11. package/dist/cjs/utils/formatHintLog.js +17 -0
  12. package/dist/cjs/utils/projectInfo.js +1 -1
  13. package/dist/esm/node/plugin/plugins/autoFullBuild.js +15 -7
  14. package/dist/esm/node/plugin/shared/loggerNotProd/log.d.ts +2 -0
  15. package/dist/esm/node/plugin/shared/loggerNotProd/log.js +1 -0
  16. package/dist/esm/node/plugin/shared/loggerNotProd.js +6 -7
  17. package/dist/esm/node/plugin/shared/loggerVite.js +3 -0
  18. package/dist/esm/node/prerender/runPrerender.js +17 -2
  19. package/dist/esm/node/runtime/globalContext/loadImportBuild.js +1 -5
  20. package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError/errors.d.ts +1 -0
  21. package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError/errors.js +17 -0
  22. package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +13 -0
  23. package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.js +321 -0
  24. package/dist/esm/node/runtime/renderPage/loggerProd.d.ts +2 -0
  25. package/dist/esm/node/runtime/renderPage/loggerProd.js +8 -0
  26. package/dist/esm/node/runtime/utils.d.ts +2 -1
  27. package/dist/esm/node/runtime/utils.js +2 -1
  28. package/dist/esm/utils/formatHintLog.d.ts +2 -0
  29. package/dist/esm/utils/formatHintLog.js +14 -0
  30. package/dist/esm/utils/projectInfo.d.ts +2 -2
  31. package/dist/esm/utils/projectInfo.js +1 -1
  32. package/package.json +2 -2
  33. package/dist/cjs/utils/autoRetry.js +0 -23
  34. package/dist/esm/utils/autoRetry.d.ts +0 -2
  35. package/dist/esm/utils/autoRetry.js +0 -20
@@ -10,6 +10,7 @@ const runPrerender_js_1 = require("../../prerender/runPrerender.js");
10
10
  const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
11
11
  const isViteCliCall_js_1 = require("../shared/isViteCliCall.js");
12
12
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
13
+ const logHintForCjsEsmError_js_1 = require("../../runtime/renderPage/logHintForCjsEsmError.js");
13
14
  let forceExit = false;
14
15
  function autoFullBuild() {
15
16
  let config;
@@ -76,13 +77,20 @@ async function triggerFullBuild(config, configVike, bundle) {
76
77
  ...configFromCli?.build
77
78
  }
78
79
  };
79
- await (0, vite_1.build)({
80
- ...configInline,
81
- build: {
82
- ...configInline.build,
83
- ssr: true
84
- }
85
- });
80
+ try {
81
+ await (0, vite_1.build)({
82
+ ...configInline,
83
+ build: {
84
+ ...configInline.build,
85
+ ssr: true
86
+ }
87
+ });
88
+ }
89
+ catch (err) {
90
+ console.error(err);
91
+ (0, logHintForCjsEsmError_js_1.logHintForCjsEsmError)(err);
92
+ process.exit(1);
93
+ }
86
94
  if (configVike.prerender && !configVike.prerender.disableAutoRun) {
87
95
  await (0, runPrerender_js_1.runPrerenderFromAutoFullBuild)({ viteConfig: configInline });
88
96
  forceExit = true;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.screenHasErrors = exports.clearScreen = exports.isFirstLog = exports.logDirectly = exports.logWithVikeTag = exports.logWithViteTag = void 0;
6
+ exports.applyViteSourceMapToStackTrace = exports.screenHasErrors = exports.clearScreen = exports.isFirstLog = exports.logDirectly = exports.logWithVikeTag = exports.logWithViteTag = void 0;
7
7
  const utils_js_1 = require("../../utils.js");
8
8
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
9
  const isErrorDebug_js_1 = require("../isErrorDebug.js");
@@ -78,6 +78,7 @@ function applyViteSourceMapToStackTrace(thing) {
78
78
  // Apply Vite's source maps
79
79
  viteDevServer.ssrFixStacktrace(thing);
80
80
  }
81
+ exports.applyViteSourceMapToStackTrace = applyViteSourceMapToStackTrace;
81
82
  function prependTags(msg, projectTag, category, logType) {
82
83
  const color = (s) => {
83
84
  if (logType === 'error' && !hasRed(msg))
@@ -22,6 +22,7 @@ const log_js_1 = require("./loggerNotProd/log.js");
22
22
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
23
23
  const isNewError_js_1 = require("../../runtime/renderPage/isNewError.js");
24
24
  const isConfigInvalid_js_1 = require("../../runtime/renderPage/isConfigInvalid.js");
25
+ const loggerProd_js_1 = require("../../runtime/renderPage/loggerProd.js");
25
26
  (0, utils_js_1.assertIsNotProductionRuntime)();
26
27
  (0, loggerRuntime_js_1.overwriteRuntimeProductionLogger)(logRuntimeError, logRuntimeInfo);
27
28
  (0, utils_js_1.overwriteAssertProductionLogger)(assertLogger);
@@ -105,6 +106,7 @@ function logErr(err, httpRequestId = null) {
105
106
  logFallbackErrIntro(category);
106
107
  }
107
108
  (0, log_js_1.logDirectly)(err, 'error');
109
+ (0, loggerProd_js_1.onRuntimeError)(err);
108
110
  }
109
111
  function logConfigError(err) {
110
112
  clearLogs({ clearAlsoIfConfigIsInvalid: true });
@@ -158,6 +160,7 @@ function handleAssertMsg(err, category) {
158
160
  return true;
159
161
  }
160
162
  function assertLogger(thing, logType) {
163
+ (0, log_js_1.applyViteSourceMapToStackTrace)(thing);
161
164
  const category = getCategory();
162
165
  const res = (0, utils_js_1.getAssertErrMsg)(thing);
163
166
  /* Risk of infinite loop
@@ -198,11 +201,7 @@ function logErrorDebugNote() {
198
201
  return;
199
202
  store.errorDebugNoteAlreadyShown = true;
200
203
  }
201
- const msg = picocolors_1.default.dim([
202
- '┌──────────────────────────────────────────────────────────┐',
203
- "│ Error isn't helpful? See https://vike.dev/errors#verbose │",
204
- '└──────────────────────────────────────────────────────────┘'
205
- ].join('\n'));
204
+ const msg = picocolors_1.default.dim((0, utils_js_1.formatHintLog)("Error isn't helpful? See https://vike.dev/errors#verbose"));
206
205
  (0, log_js_1.logDirectly)(msg, 'error');
207
206
  }
208
207
  exports.logErrorDebugNote = logErrorDebugNote;
@@ -7,6 +7,7 @@ const errorWithCodeSnippet_js_1 = require("./loggerNotProd/errorWithCodeSnippet.
7
7
  const getHttpRequestAsyncStore_js_1 = require("./getHttpRequestAsyncStore.js");
8
8
  const removeSuperfluousViteLog_js_1 = require("./loggerVite/removeSuperfluousViteLog.js");
9
9
  const isErrorDebug_js_1 = require("./isErrorDebug.js");
10
+ const loggerProd_js_1 = require("../../runtime/renderPage/loggerProd.js");
10
11
  function improveViteLogs(config) {
11
12
  intercept('info', config);
12
13
  intercept('warn', config);
@@ -48,6 +49,8 @@ function intercept(logType, config) {
48
49
  // Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
49
50
  const prependViteTag = options.timestamp || !!store?.httpRequestId;
50
51
  (0, loggerNotProd_js_1.logViteAny)(msg, logType, store?.httpRequestId ?? null, prependViteTag);
52
+ if (options.error)
53
+ (0, loggerProd_js_1.onRuntimeError)(options.error);
51
54
  };
52
55
  }
53
56
  function cleanFirstViteLog(msg) {
@@ -51,16 +51,31 @@ const loadUserFilesServerSide_js_1 = require("../runtime/renderPage/loadUserFile
51
51
  const getHook_js_1 = require("../../shared/hooks/getHook.js");
52
52
  const noRouteMatch_js_1 = require("../../shared/route/noRouteMatch.js");
53
53
  const getVikeConfig_js_1 = require("../plugin/plugins/importUserCode/v1-design/getVikeConfig.js");
54
+ const logHintForCjsEsmError_js_1 = require("../runtime/renderPage/logHintForCjsEsmError.js");
54
55
  async function runPrerenderFromAPI(options = {}) {
55
56
  await runPrerender(options, 'prerender()');
56
57
  }
57
58
  exports.runPrerenderFromAPI = runPrerenderFromAPI;
58
59
  async function runPrerenderFromCLI(options) {
59
- await runPrerender(options, '$ vike prerender');
60
+ try {
61
+ await runPrerender(options, '$ vike prerender');
62
+ }
63
+ catch (err) {
64
+ console.error(err);
65
+ (0, logHintForCjsEsmError_js_1.logHintForCjsEsmError)(err);
66
+ process.exit(1);
67
+ }
60
68
  }
61
69
  exports.runPrerenderFromCLI = runPrerenderFromCLI;
62
70
  async function runPrerenderFromAutoFullBuild(options) {
63
- await runPrerender(options, null);
71
+ try {
72
+ await runPrerender(options, null);
73
+ }
74
+ catch (err) {
75
+ console.error(err);
76
+ (0, logHintForCjsEsmError_js_1.logHintForCjsEsmError)(err);
77
+ process.exit(1);
78
+ }
64
79
  }
65
80
  exports.runPrerenderFromAutoFullBuild = runPrerenderFromAutoFullBuild;
66
81
  async function runPrerender(options, manuallyTriggered) {
@@ -13,10 +13,6 @@ exports.setImportBuildGetters = setImportBuildGetters;
13
13
  async function loadImportBuild(outDir) {
14
14
  if (!buildGetters.getters) {
15
15
  await (0, loadServerBuild_js_1.loadServerBuild)(outDir);
16
- // Await dist/server/importBuild.cjs
17
- await (0, utils_js_1.autoRetry)(() => {
18
- (0, utils_js_1.assert)(buildGetters.getters);
19
- }, 2000);
20
16
  (0, utils_js_1.assert)(buildGetters.getters);
21
17
  }
22
18
  const [pageFiles, clientManifest, pluginManifest] = await Promise.all([
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errror_cannot_use_import_outside_of_module = void 0;
4
+ // https://github.com/vikejs/vike/discussions/571#discussioncomment-6137618
5
+ exports.errror_cannot_use_import_outside_of_module = `
6
+ import{useRunner as e}from"react-runner";export*from"react-runner";import t,{useState as r,useEffect as n,Fragment as a,useCallback as l,useRef as o,useMemo as c,createContext as s,useContext as i}from"react";import p from"react-simple-code-editor";import m,{Prism as u}from"prism-react-renderer";function g(){return g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},g.apply(this,arguments)}function y(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}const d=["initialCode","transformCode"],h=t=>{let{initialCode:a="",transformCode:l}=t,o=y(t,d);const[c,s]=r(a),{element:i,error:p}=e(g({code:l?l(c):c},o));return n(()=>{s(a)},[a]),{element:i,error:p,code:c,onChange:s}},f={plain:{color:"#ffffff",backgroundColor:"#282c34"},styles:[{types:["comment","block-comment","prolog","doctype","cdata"],style:{color:"#b2b2b2"}},{types:["property","number","function-name","constant","symbol","deleted"],style:{color:"#5a9bcf"}},{types:["boolean"],style:{color:"#ff8b50"}},{types:["tag"],style:{color:"#fc929e"}},{types:["string","attr-value"],style:{color:"#8dc891"}},{types:["punctuation"],style:{color:"#88c6Be"}},{types:["selector","char","builtin","inserted"],style:{color:"#d8dee9"}},{types:["function"],style:{color:"#79b6f2"}},{types:["operator","entity","url","variable"],style:{color:"#d7deea"}},{types:["keyword"],style:{color:"#c5a5c5"}},{types:["atrule","class-name"],style:{color:"#fac863"}},{types:["important"],style:{fontWeight:"400"}},{types:["bold"],style:{fontWeight:"700"}},{types:["italic"],style:{fontStyle:"italic"}},{types:["entity"],style:{cursor:"help"}},{types:["namespace"],style:{opacity:.7}}]},b=["children","language","theme","Prism","padding","noWrapper","noWrap","className","style"],C=e=>{let{children:r,language:n="jsx",theme:l=f,Prism:o=u,padding:c=10,noWrapper:s,noWrap:i,className:p,style:d}=e,h=y(e,b);/*#__PURE__*/return t.createElement(m,{code:r||"",language:n,Prism:o,theme:l},({className:e,style:r,tokens:n,getLineProps:l,getTokenProps:o})=>{const m=n.map((e,r)=>/*#__PURE__*/t.createElement(a,{key:r},/*#__PURE__*/t.createElement("span",l({line:e}),e.map((e,r)=>/*#__PURE__*/t.createElement("span",o({token:e,key:r})))),"\\n"));return s?m:/*#__PURE__*/t.createElement("pre",g({className:p?:e,style:g({},r,{margin:0,padding:c,whiteSpace:i?"pre":"pre-wrap"},d)},h),m)})},v=["defaultValue","value","language","theme","Prism","highlight","padding","onChange"],E=e=>{let{defaultValue:n,value:a,language:s="jsx",theme:i=f,Prism:m,highlight:u,padding:d=10,onChange:h}=e,b=y(e,v);const[E,P]=r(n||""),k=void 0!==a,W=l(e=>/*#__PURE__*/t.createElement(C,{language:s,theme:i,Prism:m,noWrapper:!0},e),[s,i,m]),j=o(h);j.current=h;const x=l(e=>{k||P(e),null==j.current||j.current(e)},[k]),O=c(()=>g({},i.plain,b.style),[i.plain,b.style]);/*#__PURE__*/return t.createElement(p,g({},b,{highlight:u||W,padding:d,value:k?a:E,onValueChange:x,style:O}))},P=s({}),k=()=>i(P),W=["children","code","language","theme"],j=e=>{let{children:r,code:n="",language:a="jsx",theme:l=f}=e,o=y(e,W);const{element:c,error:s,code:i,onChange:p}=h(g({initialCode:n},o));/*#__PURE__*/return t.createElement(P.Provider,{value:{element:c,error:s,code:i,onChange:p,language:a,theme:l}},r)},x=e=>{const{code:r,language:n,theme:a,onChange:l}=k();/*#__PURE__*/return t.createElement(E,g({value:r,language:n,theme:a,onChange:l},e))},O=["Component"],w=e=>{let{Component:r="div"}=e,n=y(e,O);const{element:a}=k();/*#__PURE__*/return t.createElement(r,n,a)},N=e=>{const{error:r}=k();return r?/*#__PURE__*/t.createElement("pre",e,r):/*#__PURE__*/t.createElement(t.Fragment,null)};export{C as CodeBlock,E as CodeEditor,P as LiveContext,x as LiveEditor,N as LiveError,w as LivePreview,j as LiveProvider,f as defaultTheme,k as useLiveContext,h as useLiveRunner};
7
+ ^^^^^^
8
+
9
+ SyntaxError: Cannot use import statement outside a module
10
+ at Object.compileFunction (node:vm:360:18)
11
+ at wrapSafe (node:internal/modules/cjs/loader:1084:15)
12
+ at Module._compile (node:internal/modules/cjs/loader:1119:27)
13
+ at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
14
+ at Module.load (node:internal/modules/cjs/loader:1033:32)
15
+ at Function.Module._load (node:internal/modules/cjs/loader:868:12)
16
+ at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
17
+ at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
18
+ at processTicksAndRejections (node:internal/process/task_queues:96:5)
19
+ at async Promise.all (index 0)
20
+ `;
@@ -0,0 +1,326 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getHint = exports.isReactInvalidComponentError = exports.isCjsEsmError = exports.logHintForCjsEsmError = void 0;
7
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
8
+ const utils_js_1 = require("../utils.js");
9
+ function logHintForCjsEsmError(error) {
10
+ /* Collect errors for ./logHintForCjsEsmError.spec.ts
11
+ collectError(error)
12
+ //*/
13
+ const hint = getHint(error);
14
+ if (hint)
15
+ logHint(hint);
16
+ }
17
+ exports.logHintForCjsEsmError = logHintForCjsEsmError;
18
+ function getHint(error) {
19
+ if (isReactInvalidComponentError(error)) {
20
+ const hint = 'To fix this error, see https://vike.dev/broken-npm-package#react-invalid-component';
21
+ return hint;
22
+ }
23
+ const res = isCjsEsmError(error);
24
+ if (res) {
25
+ const packageNames = res === true ? null : res;
26
+ const hint = [
27
+ 'Error could be a CJS/ESM issue, consider ',
28
+ !packageNames || packageNames.length === 0
29
+ ? 'using'
30
+ : `adding ${(0, utils_js_1.joinEnglish)(packageNames.map((p) => picocolors_1.default.cyan(p)), 'or')} to`,
31
+ ` ${picocolors_1.default.cyan('ssr.noExternal')}`,
32
+ ', see https://vike.dev/broken-npm-package'
33
+ ].join('');
34
+ return hint;
35
+ }
36
+ return null;
37
+ }
38
+ exports.getHint = getHint;
39
+ function logHint(hint) {
40
+ hint = (0, utils_js_1.formatHintLog)(hint);
41
+ console.error(hint);
42
+ }
43
+ function isReactInvalidComponentError(error) {
44
+ const anywhere = getAnywhere(error);
45
+ return includes(anywhere, 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)');
46
+ }
47
+ exports.isReactInvalidComponentError = isReactInvalidComponentError;
48
+ /**
49
+ * `false` -> noop
50
+ * `true` -> generic message
51
+ * `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
52
+ */
53
+ function isCjsEsmError(error) {
54
+ const message = getErrMessage(error);
55
+ const anywhere = getAnywhere(error);
56
+ const packageName_stack1 = getPackageName_stack1(error);
57
+ const packageName_stack2 = getPackageName_stack2(error);
58
+ const isRelatedToNodeModules = !!packageName_stack1 || !!packageName_stack2 || includesNodeModules(message);
59
+ // const relatedNpmPackages = normalize([packageName_stack1, packageName_stack2, extractFromNodeModulesPath(message)])
60
+ // ERR_UNSUPPORTED_DIR_IMPORT
61
+ {
62
+ const packageNames = parseNodeModulesPathMessage('ERR_UNSUPPORTED_DIR_IMPORT', anywhere);
63
+ if (packageNames)
64
+ return packageNames;
65
+ }
66
+ // ERR_UNKNOWN_FILE_EXTENSION
67
+ {
68
+ const packageNames = parseUnkownFileExtensionMessage(anywhere);
69
+ if (packageNames)
70
+ return packageNames;
71
+ }
72
+ {
73
+ const packageNames = parseNodeModulesPathMessage('ERR_UNKNOWN_FILE_EXTENSION', anywhere);
74
+ if (packageNames)
75
+ return packageNames;
76
+ }
77
+ {
78
+ const packageNames = parseNodeModulesPathMessage('is not exported', anywhere);
79
+ if (packageNames)
80
+ return packageNames;
81
+ }
82
+ // Using CJS inside ESM modules.
83
+ if (includes(anywhere, 'require is not a function') ||
84
+ includes(anywhere, 'exports is not defined') ||
85
+ includes(anywhere, 'module is not defined') ||
86
+ includes(anywhere, 'window is not defined') ||
87
+ includes(anywhere, 'not defined in ES')) {
88
+ if (packageName_stack1)
89
+ return packageName_stack1;
90
+ }
91
+ if (includes(anywhere, "Unexpected token 'export'")) {
92
+ if (packageName_stack2)
93
+ return packageName_stack2;
94
+ if (packageName_stack1)
95
+ return packageName_stack1;
96
+ }
97
+ // ERR_REQUIRE_ESM
98
+ if (includes(anywhere, 'ERR_REQUIRE_ESM')) {
99
+ /* The issue is the importer, not the importee.
100
+ if (relatedNpmPackages) return relatedNpmPackages
101
+ */
102
+ {
103
+ if (packageName_stack1)
104
+ return packageName_stack1;
105
+ }
106
+ if (isRelatedToNodeModules)
107
+ return true;
108
+ }
109
+ /* The following two wrongfully match user land errors
110
+ {
111
+ const packageNames = parseNodeModulesPath('ERR_REQUIRE_ESM', anywhere)
112
+ if (packageNames) return packageNames
113
+ }
114
+ {
115
+ const packageNames = parseNodeModulesPath('Must use import', anywhere)
116
+ if (packageNames) return packageNames
117
+ }
118
+ */
119
+ // `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
120
+ {
121
+ const packageNames = parseImportFrom(anywhere);
122
+ if (packageNames)
123
+ return packageNames;
124
+ }
125
+ if (includes(anywhere, 'Cannot read properties of undefined')) {
126
+ if (isRelatedToNodeModules) {
127
+ /* We return true because relatedNpmPackages points to the importer but the problematic npm package is the importee
128
+ if (relatedNpmPackages) return relatedNpmPackages
129
+ */
130
+ return true;
131
+ }
132
+ }
133
+ // ERR_MODULE_NOT_FOUND
134
+ {
135
+ const packageNames = parseCannotFindMessage(anywhere);
136
+ if (packageNames)
137
+ return packageNames;
138
+ }
139
+ if (
140
+ // `SyntaxError: Cannot use import statement outside a module`.
141
+ // Since user code is always ESM, this error must always originate from an npm package.
142
+ includes(anywhere, 'Cannot use import statement') ||
143
+ // `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
144
+ // It seems that this always points to an npm package import.
145
+ /Named export.*not found/i.test(anywhere)) {
146
+ /* We return true even if fromNodeModules is false because the errors always relate to npm packages.
147
+ if (fromNodeModules) return true
148
+ */
149
+ return true;
150
+ }
151
+ return false;
152
+ }
153
+ exports.isCjsEsmError = isCjsEsmError;
154
+ function parseCannotFindMessage(str) {
155
+ const match = /Cannot find \S+ '(\S+)' imported from (\S+)/.exec(str);
156
+ if (!match)
157
+ return false;
158
+ // const packageNameCannotFind = extractFromPath(match[1]!)
159
+ const packageNameFrom = extractFromPath(match[2]);
160
+ return normalize([
161
+ // packageNameCannotFind,
162
+ packageNameFrom
163
+ ]);
164
+ }
165
+ function parseUnkownFileExtensionMessage(str) {
166
+ const match = /Unknown file extension "\S+" for (\S+)/.exec(str);
167
+ if (!match)
168
+ return false;
169
+ const filePath = match[1];
170
+ const packageName = extractFromPath(filePath);
171
+ return normalize([packageName]);
172
+ }
173
+ function parseImportFrom(str) {
174
+ const match = /\bimport\b.*?\bfrom\b\s*?"(.+?)"/.exec(str);
175
+ if (!match)
176
+ return false;
177
+ const importPath = match[1];
178
+ const packageName = extractFromPath(importPath);
179
+ return normalize([packageName]);
180
+ }
181
+ function parseNodeModulesPathMessage(begin, str) {
182
+ str = str.replaceAll('\\', '/');
183
+ const regex = new RegExp(`${begin}.*(node_modules\\/\\S+)`);
184
+ const match = regex.exec(str);
185
+ if (!match)
186
+ return false;
187
+ const importPath = match[1];
188
+ return extractFromNodeModulesPath(importPath);
189
+ }
190
+ function getPackageName_stack1(err) {
191
+ const errStack = getErrStack(err);
192
+ if (!errStack)
193
+ return false;
194
+ const firstLineStackTrace = errStack.split('\n').filter((line) => line.startsWith(' at '))[0];
195
+ if (!firstLineStackTrace)
196
+ return false;
197
+ return extractFromNodeModulesPath(firstLineStackTrace);
198
+ }
199
+ /** See https://github.com/brillout/repro_node-syntax-error#nodejs-behavior */
200
+ function getPackageName_stack2(err) {
201
+ const errStack = getErrStack(err);
202
+ if (!errStack)
203
+ return false;
204
+ const firstLine = errStack.trim().split('\n')[0];
205
+ return extractFromNodeModulesPath(firstLine);
206
+ }
207
+ function extractFromPath(filePath) {
208
+ (0, utils_js_1.assert)(filePath);
209
+ filePath = clean(filePath);
210
+ filePath = filePath.replaceAll('\\', '/');
211
+ let packageName;
212
+ if (!filePath.includes('node_modules/')) {
213
+ packageName = filePath;
214
+ if (packageName.startsWith('/'))
215
+ return null;
216
+ if (packageName.startsWith('.'))
217
+ return null;
218
+ }
219
+ else {
220
+ packageName = filePath.split('node_modules/').pop();
221
+ // This assert is fairly risk, we should eventually remove it
222
+ (0, utils_js_1.assert)(!packageName.startsWith('.'));
223
+ // This assert is fairly risk, we should eventually remove it
224
+ (0, utils_js_1.assert)(!packageName.startsWith('/'));
225
+ }
226
+ if (!packageName)
227
+ return null;
228
+ packageName = packageName.split('/').slice(0, 2).join('/');
229
+ if (!packageName.startsWith('@')) {
230
+ packageName = packageName.split('/')[0];
231
+ }
232
+ packageName = clean(packageName);
233
+ (0, utils_js_1.assert)(!['vite', 'vike'].includes(packageName));
234
+ return packageName;
235
+ }
236
+ function clean(packageName) {
237
+ const b = ['"', "'", '(', ')'];
238
+ if (b.includes(packageName[0])) {
239
+ packageName = packageName.slice(1);
240
+ }
241
+ if (b.includes(packageName[packageName.length - 1])) {
242
+ packageName = packageName.slice(0, -1);
243
+ }
244
+ return packageName;
245
+ }
246
+ function extractFromNodeModulesPath(str) {
247
+ if (!includesNodeModules(str))
248
+ return false;
249
+ const packageName = extractFromPath(str);
250
+ (0, utils_js_1.assert)(packageName);
251
+ return normalize([packageName]);
252
+ }
253
+ function includes(str1, str2) {
254
+ return !!str1 && str1.toLowerCase().includes(str2.toLowerCase());
255
+ }
256
+ function includesNodeModules(str) {
257
+ if (!str)
258
+ return false;
259
+ str = str.replaceAll('\\', '/');
260
+ if (!str.includes('node_modules/'))
261
+ return false;
262
+ if (str.includes('node_modules/vite/'))
263
+ return false;
264
+ return true;
265
+ }
266
+ function normalize(packageNames) {
267
+ const result = (0, utils_js_1.unique)(packageNames.filter(utils_js_1.isNotNullish));
268
+ if (result.length === 0)
269
+ return false;
270
+ return result;
271
+ }
272
+ function getErrMessage(err) {
273
+ if (!(0, utils_js_1.isObject)(err))
274
+ return null;
275
+ if (!err.message)
276
+ return null;
277
+ if (typeof err.message !== 'string')
278
+ return null;
279
+ return err.message;
280
+ }
281
+ function getErrCode(err) {
282
+ if (!(0, utils_js_1.isObject)(err))
283
+ return null;
284
+ if (!err.code)
285
+ return null;
286
+ if (typeof err.code !== 'string')
287
+ return null;
288
+ return err.code;
289
+ }
290
+ function getErrStack(err) {
291
+ if (!(0, utils_js_1.isObject)(err))
292
+ return null;
293
+ if (!err.stack)
294
+ return null;
295
+ if (typeof err.stack !== 'string')
296
+ return null;
297
+ return err.stack;
298
+ }
299
+ function getAnywhere(error) {
300
+ const code = getErrCode(error);
301
+ const message = getErrMessage(error);
302
+ const stack = getErrStack(error);
303
+ const anywhere = [code, message, stack].filter(Boolean).join('\n');
304
+ return anywhere;
305
+ }
306
+ function collectError(err) {
307
+ console.log([
308
+ '{',
309
+ ` message: ${JSON.stringify(err.message)},`,
310
+ ` code: ${JSON.stringify(err.code)},`,
311
+ ' stack: `\n' + err.stack + '\n`',
312
+ '}'
313
+ ].join('\n'));
314
+ /* For reproductions using older vite-plugin-ssr versions, do one of the following.
315
+ - If upon pre-rendering:https: //github.com/brillout/repro_node-syntax-error#error-catched-by-vite-plugin-ssr
316
+ - Inject the logger inside `catch` in node_modules/vite-plugin-ssr/dist/esm/node/runtime/renderPage.js
317
+ - Inject the following inside `configResolved(config_)` at node_modules/vite-plugin-ssr/dist/cjs/node/plugin/plugins/devConfig/index.js
318
+ ```js
319
+ config_.logger.error = (msg, options) => {
320
+ const { error } = options;
321
+ if (error) return;
322
+ console.log(...);
323
+ };
324
+ ```
325
+ */
326
+ }
@@ -5,11 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.logErrorProd = void 0;
8
+ exports.onRuntimeError = exports.logErrorProd = void 0;
9
9
  const abort_js_1 = require("../../../shared/route/abort.js");
10
10
  const isNewError_js_1 = require("./isNewError.js");
11
11
  const utils_js_1 = require("../utils.js");
12
12
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
13
+ const logHintForCjsEsmError_js_1 = require("./logHintForCjsEsmError.js");
13
14
  function logErrorProd(err, _httpRquestId) {
14
15
  (0, utils_js_1.warnIfErrorIsNotObject)(err);
15
16
  (0, isNewError_js_1.setAlreadyLogged)(err);
@@ -19,5 +20,12 @@ function logErrorProd(err, _httpRquestId) {
19
20
  // We ensure we print a string; Cloudflare Workers doesn't seem to properly stringify `Error` objects.
20
21
  const errStr = (0, utils_js_1.isObject)(err) && 'stack' in err ? String(err.stack) : String(err);
21
22
  console.error(picocolors_1.default.red(errStr));
23
+ onRuntimeError(err);
22
24
  }
23
25
  exports.logErrorProd = logErrorProd;
26
+ // Every server-side runtime error is expected to go through onRuntimeError(). (In principle, any runtime error is (or at least should) be catched by Vike, otherwise Vike couldn't render the error page.)
27
+ function onRuntimeError(err) {
28
+ // The more runtime errors we pass to logHintForCjsEsmError() the better.
29
+ (0, logHintForCjsEsmError_js_1.logHintForCjsEsmError)(err);
30
+ }
31
+ exports.onRuntimeError = onRuntimeError;
@@ -67,4 +67,5 @@ __exportStar(require("../../utils/warnIfErrorIsNotObject.js"), exports);
67
67
  __exportStar(require("../../utils/stripAnsi.js"), exports);
68
68
  __exportStar(require("../../utils/getTerminWidth.js"), exports);
69
69
  __exportStar(require("../../utils/truncateString.js"), exports);
70
- __exportStar(require("../../utils/autoRetry.js"), exports);
70
+ __exportStar(require("../../utils/formatHintLog.js"), exports);
71
+ __exportStar(require("../../utils/joinEnglish.js"), exports);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatHintLog = void 0;
4
+ const assert_js_1 = require("./assert.js");
5
+ const stripAnsi_js_1 = require("./stripAnsi.js");
6
+ function formatHintLog(msg) {
7
+ (0, assert_js_1.assert)(msg.length > 0);
8
+ const msgLength = (0, stripAnsi_js_1.stripAnsi)(msg).length;
9
+ const sep = '─'.repeat(msgLength);
10
+ return [
11
+ // prettier-ignore
12
+ `┌─${sep}─┐`,
13
+ `│ ${msg} │`,
14
+ `└─${sep}─┘`
15
+ ].join('\n');
16
+ }
17
+ exports.formatHintLog = formatHintLog;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
4
  const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
5
- const PROJECT_VERSION = '0.4.153-commit-3e842bb';
5
+ const PROJECT_VERSION = '0.4.153-commit-e631897';
6
6
  exports.PROJECT_VERSION = PROJECT_VERSION;
7
7
  const projectInfo = {
8
8
  projectName: 'Vike',
@@ -5,6 +5,7 @@ import { runPrerenderFromAutoFullBuild, runPrerender_forceExit } from '../../pre
5
5
  import { getConfigVike } from '../../shared/getConfigVike.js';
6
6
  import { isViteCliCall, getViteConfigFromCli } from '../shared/isViteCliCall.js';
7
7
  import pc from '@brillout/picocolors';
8
+ import { logHintForCjsEsmError } from '../../runtime/renderPage/logHintForCjsEsmError.js';
8
9
  let forceExit = false;
9
10
  function autoFullBuild() {
10
11
  let config;
@@ -70,13 +71,20 @@ async function triggerFullBuild(config, configVike, bundle) {
70
71
  ...configFromCli?.build
71
72
  }
72
73
  };
73
- await build({
74
- ...configInline,
75
- build: {
76
- ...configInline.build,
77
- ssr: true
78
- }
79
- });
74
+ try {
75
+ await build({
76
+ ...configInline,
77
+ build: {
78
+ ...configInline.build,
79
+ ssr: true
80
+ }
81
+ });
82
+ }
83
+ catch (err) {
84
+ console.error(err);
85
+ logHintForCjsEsmError(err);
86
+ process.exit(1);
87
+ }
80
88
  if (configVike.prerender && !configVike.prerender.disableAutoRun) {
81
89
  await runPrerenderFromAutoFullBuild({ viteConfig: configInline });
82
90
  forceExit = true;
@@ -4,6 +4,7 @@ export { logDirectly };
4
4
  export { isFirstLog };
5
5
  export { clearScreen };
6
6
  export { screenHasErrors };
7
+ export { applyViteSourceMapToStackTrace };
7
8
  import type { LogCategory, LogType } from '../loggerNotProd.js';
8
9
  import type { ResolvedConfig } from 'vite';
9
10
  declare let isFirstLog: boolean;
@@ -12,3 +13,4 @@ declare function logWithVikeTag(msg: string, logType: LogType, category: LogCate
12
13
  declare function logWithViteTag(msg: string, logType: LogType, category: LogCategory | null): void;
13
14
  declare function logDirectly(thing: unknown, logType: LogType): void;
14
15
  declare function clearScreen(viteConfig: ResolvedConfig): void;
16
+ declare function applyViteSourceMapToStackTrace(thing: unknown): void;
@@ -4,6 +4,7 @@ export { logDirectly };
4
4
  export { isFirstLog };
5
5
  export { clearScreen };
6
6
  export { screenHasErrors };
7
+ export { applyViteSourceMapToStackTrace };
7
8
  import { assert, projectInfo, stripAnsi, hasProp, assertIsNotProductionRuntime } from '../../utils.js';
8
9
  import pc from '@brillout/picocolors';
9
10
  import { isErrorDebug } from '../isErrorDebug.js';