-
Notifications
You must be signed in to change notification settings - Fork 27.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected token import when using TypeScript and Jest examples #3663
Comments
Next 5 just went out, can you try it out and the plugin for typescript too ? |
Heya. I’m experimenting with Next 5, and I have come across a few oddities. The good news is that I was able to get the typescript and scss plugins to work in dev mode…
The bad? I’ve created a demo project to highlight some of those concerns:
https://github.com/TheRobBrennan/demo-nextjs-v5 <https://github.com/TheRobBrennan/demo-nextjs-v5>
The two big issues I’ve encountered so far are:
SCSS is working for dev mode but NOT for production
Redux is connected and works within the app; but it DOES NOT WORK with simple testing...why? pages/redux.test.tsx has a test that calls attention to this for the time being.
Of note, I’m using the same test that worked fine in Next 4, so…something is a little different…Not sure whose domain that falls into, though.
Rob Brennan | rob@therobbrennan.com
Phone (360) 531-3830
Skype The.Rob.Brennan
Web http://www.woatw.com
http://www.therobbrennan.com
… On Feb 5, 2018, at 3:00 PM, Luis Fernando Alvarez D. ***@***.***> wrote:
Next 5 just went out, can you try it out and the plugin for typescript <https://github.com/zeit/next-plugins/tree/master/packages/next-typescript> too ?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#3663 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AD2AGgef1VADTPN9j6QbtSnjcTkDHdcGks5tR4gIgaJpZM4R3pba>.
|
I'm running into an issue that might or might not be related to this. I'm using mapbox-gl. Usually one would simply import the commonjs entrypoint, but instead I'm importing import MapboxMap from 'mapbox-gl/src/ui/map'; Since module.exports = {
webpack: config => {
config.module.rules.push({
test: /mapbox\-gl\/src\/.+\.js$/,
loader: 'babel-loader',
options: {
presets: [
'babel-preset-flow',
'babel-preset-env',
],
plugins: [
'babel-plugin-static-fs',
'babel-plugin-transform-class-properties'
]
}
});
return config;
}
}; running
These |
@TheRobBrennan is this still relevant? |
@timneutkens I don't believe so. Everything seems to be in a great place. |
how closed this issue? I run into the same issue as well. |
same |
same here with 6.0.0-canary.2 / node 8.11.1 Spent some time trying different versions (starting with a merge of copy+paste from examples). e.g:
No avail ... |
The example project works fine. Trying to get it to work in an actual project always fails. My theory: There is something wrong with the compile steps and actual compile errors get swallowed. Then afterwards it tries to use the uncompiled .tsx and fails. |
@timneutkens @TheRobBrennan can we get this issue re-opened or should we create a new one? |
Sure - reopened 😊 |
I was using "with-jest-typescript" example and ran into this problem, looks like changing tsconfig.json compilerOptions.jsx from "preserve" to "react" gets the tests running, but breaks the app. So ended up with custom tsconfig.jest.json
and updated the test.config.js
|
Upon @makstr 's suggestion, if you face trouble resolving modules, try {
"extends": "./tsconfig",
"compilerOptions": {
"jsx": "react",
"module": "commonjs"
}
} as mentioned in ts-jest doc. |
Hello! I ran into an issue using typescript and jest with next 6.0.0. I was able to work through fixing it and I wanted to share my solution back to next.js, by upgrading the with-jest-typescript example to next 6.0.0. The steps I followed were: 1. `npx babel-upgrade --write` which added babel-core@^7.0.0-bridge.0 to allow jest's babel 6 to play nice with next's babel 7 2. Remove `ts-jest` and replace with `babel-jest` to use babel to transform the typescript code, as is done when the dev and production builds run 3. Update the babelrc to use commonjs modules in test mode to be compatible with jest Also, I removed the `NODE_ENV=test` on the jest task, because jest sets the env to test anyways, and I'm on windows where this code is incorrect. The other option is to use `cross-env` but I felt it was simpler to just remove the environment override. To my knowledge, this PR would help on the following issues: #3663 #4227 #4531 #4528 #4239
Hello! I ran into an issue using typescript and jest with next 6.0.0. I was able to work through fixing it and I wanted to share my solution back to next.js, by upgrading the with-jest-typescript example to next 6.0.0. The steps I followed were: 1. `npx babel-upgrade --write` which added babel-core@^7.0.0-bridge.0 to allow jest's babel 6 to play nice with next's babel 7 2. Remove `ts-jest` and replace with `babel-jest` to use babel to transform the typescript code, as is done when the dev and production builds run 3. Update the babelrc to use commonjs modules in test mode to be compatible with jest Also, I removed the `NODE_ENV=test` on the jest task, because jest sets the env to test anyways, and I'm on windows where this code is incorrect. The other option is to use `cross-env` but I felt it was simpler to just remove the environment override. To my knowledge, this PR would help on the following issues: vercel#3663 vercel#4227 vercel#4531 vercel#4528 vercel#4239
Should be solved with the Next 7 rewrite of next/dynamic. |
I'm encountering a weird issue with either Babel or Next.js when trying to run TypeScript jest tests.
I can run the Jest test written in plain ol' JavaScript just fine, but the Footer.test.tsx file fails with an unexpected token import message:
`
PASS ./demo.test.js
FAIL components/Layout/Footer/Footer.test.tsx
● Test suite failed to run
`
Using the Next.js examples with-jest and with-typescript, I've got the following configuration in place:
// tsconfig.json { "compilerOptions": { "jsx": "react-native", "module": "commonjs", "strict": true, "target": "es2017" } }
// .babelrc { "env": { "development": { "presets": ["next/babel"] }, "production": { "presets": ["next/babel"] }, "test": { "presets": [["next/babel", { "preset-env": { "modules": "commonjs" } }]] } } }
// jest.config.js module.exports = { setupFiles: ['<rootDir>/jest.setup.js'], testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'], testRegex: '\\.test\\.*', moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], collectCoverageFrom: [ '!jest.setup.js', '**/*.{js,jsx,ts,tsx}', '!build/**', '!coverage/**' ] }
`// jest.setup.js
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
configure({ adapter: new Adapter() })
`
Expected Behavior
Shouldn't I be able to run my jest test written in TSX:
`// Footer.test.tsx
import { shallow } from 'enzyme'
import { Footer } from './Footer'
describe('Footer', () => {
)it('should render', () => {
const wrapper = shallow(
expect(wrapper).toBeDefined()
})
})
`
Current Behavior
I can run the Jest test written in plain ol' JavaScript just fine, but the Footer.test.tsx file fails with an unexpected token import message:
`
PASS ./demo.test.js
FAIL components/Layout/Footer/Footer.test.tsx
● Test suite failed to run
`
Any help would be appreciated. Thanks!!
The text was updated successfully, but these errors were encountered: