RW 0.19.5-canary.15 is broken on Windows (imports related)
See original GitHub issueI just upgraded from RW 0.18.0 to latest canary, 0.19.5-canary.15 and this is what I was greeted by 😉
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:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Let me see if I can fix it before we revert.
Fixed in v0.20.0