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

Created on 15 Oct 2020  路  8Comments  路  Source: redwoodjs/redwood

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
       },

Most helpful comment

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

All 8 comments

cc @peterp @dac09

Most likely from this PR merged earlier today https://github.com/redwoodjs/redwood/pull/1332

Most likely from this PR merged earlier today #1332

Yes, that was basically the code I reverted above

We have a catch 22 here, the above changes will break unix. (what it used to be before the PR essentially).

Maybe I can try a fix tomorrow @Tobbe if you're happy to help me test on windows?

It's the same state on Windows as on Unix as in not properly importing .ts/.tsx files

@thedavidprice is it worth reverting the PR till I can work out a better solution?

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

Hi @mnznz There was fix merged early today in this PR #1364

The most recent canary is 0.19.5-canary.16. I just checked npm and it published successfully.

If you're already on the canary, you can now target a version with yarn rw upgrade -t 0.19.5-canary.16. Let me know how it goes.

Fixed in v0.20.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wispyco picture wispyco  路  3Comments

jtoar picture jtoar  路  4Comments

Tobbe picture Tobbe  路  4Comments

hemildesai picture hemildesai  路  4Comments

freddydumont picture freddydumont  路  3Comments