question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

require.context replacement doesn't work for nested paths on Windows

See original GitHub issue

This plugin will rewrite the following

const customTabsContext = require.context('@/components/tabs', true, /^.*(.vue)$/)

to something like this when using Windows:

const customTabsContext = 
  (function() {
    var map = {
      './category1\Tab1.vue': import_context_module_0_0,
'./category1\Tab2.vue': import_context_module_0_1,
'./category2\Tab3.vue': import_context_module_0_2,

    };
    var req = function req(key) {
      return map[key] || (function() { throw new Error("Cannot find module '" + key + "'.") }());
    }
    req.keys = function() {
      return Object.keys(map);
    }
    return req;
  })()

Note that the keys in the map use backslashes \ for nested paths. However to put a backslash into a string literal you need to escape it \\. Therefore require.context won’t work for nested paths on Windows.

This works fine on Mac OS, as the keys in the map will use forward slashes /.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
IndexXuancommented, Mar 5, 2021

Release: v0.3.2

BTW I change src/lib/resolve.ts#L100 to pass my testcase, if something wrong, please feedback.

1reaction
danielelkingtoncommented, Mar 4, 2021

Will give this a go tomorrow. Thanks for creating this awesome plug-in!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building context-nested routes with React Router 6
The issue here is that the code is attempting to render two routes on the same path, but only one route can match...
Read more >
possibility to use nested routes with absolute paths ... - GitHub
I'm implementing i18n, my URLs are translated and I have to work with absolute addresses, because the translation library doesn't have access to ......
Read more >
Resolve | webpack
A list of directories where requests of server-relative URLs (starting with '/') are resolved, defaults to context configuration option. On non-Windows systems ...
Read more >
Analyze complex data types in Azure Synapse Analytics
Analyzing nested schema and arrays can involve time-consuming and complex ... deeply nested objects, you can encounter performance problems.
Read more >
Migrating to React Router v6: A complete guide
Thus, developers need to arrange the definition, so the route with the parameter comes first. Otherwise, the routes won't work as expected ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found