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.

RW 0.19.5-canary.15 is broken on Windows (imports related)

See original GitHub issue

I just upgraded from RW 0.18.0 to latest canary, 0.19.5-canary.15 and this is what I was greeted by 😉

image

All my imports are broken.

This is my temporary fix to let me use RW again.

diff --git a/packages/core/src/babelPlugins/babel-plugin-redwood-directory-named-import.ts b/packages/core/src/babelPlugins/babel-plugin-redwood-directory-named-import.ts
index aced444d..b54f3b3b 100644
--- a/packages/core/src/babelPlugins/babel-plugin-redwood-directory-named-import.ts
+++ b/packages/core/src/babelPlugins/babel-plugin-redwood-directory-named-import.ts
@@ -1,4 +1,3 @@
-import { resolveFile, ensurePosixPath } from '@redwoodjs/internal'
 import path from 'path'

 import type { PluginObj, types } from '@babel/core'
@@ -7,20 +6,13 @@ const getNewPath = (value: string, filename: string) => {
   const dirname = path.dirname(value)
   const basename = path.basename(value)

-  const indexImportPath = [dirname, basename, 'index'].join('/')
+  const newImportPath = [dirname, basename, basename].join('/')

-  const indexImportPathResolved = resolveFile(
-    path.join(path.dirname(filename), indexImportPath)
-  )
-
-  if (indexImportPathResolved) {
-    // If babel can resolve this path with the index file
-    return indexImportPathResolved
-  } else {
-    // If there isn't a index file
-    const newImportPath = [dirname, basename, basename].join('/')
-
-    return resolveFile(path.join(path.dirname(filename), newImportPath))
+  try {
+    require.resolve(path.resolve(path.dirname(filename), newImportPath))
+    return newImportPath
+  } catch (e) {
+    return null
   }
 }

@@ -43,7 +35,7 @@ export default function ({ types: t }: { types: typeof types }): PluginObj {

         const newPath = getNewPath(value, <string>filename)
         if (!newPath) return
-        const newSource = t.stringLiteral(ensurePosixPath(newPath))
+        const newSource = t.stringLiteral(value.replace(value, newPath))
         p.node.source = newSource
       },

@@ -69,7 +61,7 @@ export default function ({ types: t }: { types: typeof types }): PluginObj {

         const newPath = getNewPath(value, <string>filename)
         if (!newPath) return
-        const newSource = t.stringLiteral(ensurePosixPath(newPath))
+        const newSource = t.stringLiteral(value.replace(value, newPath))
         // @ts-expect-error - TypeDef must be outdated.
         p.node.source = newSource
       },

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
peterpcommented, Oct 15, 2020

Let me see if I can fix it before we revert.

0reactions
thedavidpricecommented, Oct 28, 2020

Fixed in v0.20.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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