Closed ai closed 5 years ago
Is it failing on a particular piece of code? Sounds like the import triing is missing an edge case perhaps
I see this error during run of any test, so I think it is not related with some specific code:
For most of the cases we have code like:
// Import will be added by ./builder/auto-import
let Container = styled.div`
position: relative;
font-size: 13px;
`
I think error can be the result of astroturf plugin options:
"allowGlobal": true,
"writeFiles": false
Unfortunately, it still doesn’t work. Tried to update to 0.8.2 and almost all the tests fail. There is no such error when a test doesn't contain styles, e.g., reducers or pure functions.
I tried to add
if (!decl) return
to node_modules/astroturf/plugin.js:182
— it works perfectly.
@jquense can I help you somehow?
@vrizo happy to take a PR we aren't hitting this error and i'm bit short on time to debug. My guess is that the import trimming logic probably assumes that the imports exist, conflict with the global option, probably just needs a guard somewhere as you noted
Yep, looks like you're right. But I think if (!decl) return
hides a true cause, because I can't replicate the problem in your tests. Moreover, our test file includes components with astroturf imports. I'm going to debug a little bit more today
@jquense Hi! Sorry for the delay, too many bugs this week. I'm still trying to investigate the problem.
First of all, we have an auto import of styled
if parser finds styled.
in a code. But I need to import { css }
manually.
{ css }
import, it failsI tried to reproduce the issue in your tests but with no luck.
So I go further and debug the file with import { css }
:
// plugin.js L173
const importNodes = file.get(IMPORTS);
const imports = [];
importNodes.forEach(path => {
console.log('DEBUG: ', path.type, path.isImportDeclaration(), t.isImportDeclaration(path))
const decl = !path.isImportDeclaration() ? path.findParent(p => p.isImportDeclaration()) : path;
Result in console:
DEBUG: ImportDeclaration false true
In this case, path.type
is ImportDeclaration, but it has no path.node
. I have minimal experience in Babel, and I can't find why path
doesn't include node
. Is it correct behavior?
Ran into the exact same problem, with the exact same solution: bailing when !decl
node_modules/astroturf/plugin.js:182
works normally. Same problem occurred for the webpack config for Storybook and 2 other packages.
So there are clearly cases where path
doesn't have a node
property but it's unclear what those cases are.
@jquense I found a reason and sent fix https://github.com/4Catalyzer/astroturf/pull/137
I updated
astroturf
and got this error during test:My Babel config: